diff --git a/src/app/_guards/auth.guard.ts b/src/app/_guards/auth.guard.ts index 15c9737..072976b 100644 --- a/src/app/_guards/auth.guard.ts +++ b/src/app/_guards/auth.guard.ts @@ -7,16 +7,19 @@ export class AuthGuard implements CanActivate { constructor(private router: Router) { } /* - Using CanActivate as route guard and simply checking if the currentUser object is inplace. + Using CanActivate as route guard and simply checking if the currentUser object is in place. This can and should be expanded to validating the token via a service to ensure validity */ canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) { + + /* In the real world I would pull this into a local class and have a service validate the token, but for the sake of the demo we'll just accept that this dude is valid*/ if (localStorage.getItem('currentUser')) { return true; } /* If not then kick them back to the login page */ - this.router.navigate( ['login'] ); + this.router.navigate(['login']); return false; } + } \ No newline at end of file diff --git a/src/app/_guards/role.guard.ts b/src/app/_guards/role.guard.ts new file mode 100644 index 0000000..c0ca243 --- /dev/null +++ b/src/app/_guards/role.guard.ts @@ -0,0 +1,25 @@ +import { Injectable } from '@angular/core'; +import { Router, CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router'; + +@Injectable() +export class RoleGuard implements CanActivate { + + constructor(private router: Router) { } + + /* + Using CanActivate as route guard and simply checking if the currentUser object is inplace. + This can and should be expanded to validating the token via a service to ensure validity + */ + canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) { + + /* In the real world I would pull this into a local class and have a service validate the token, but for the sake of the demo we'll just accept that this dude is valid*/ + if (JSON.parse(localStorage.getItem('currentUser')).role == "B5") { + return true; + } + + /* If not then kick them back to the login page */ + this.router.navigate(['login']); + return false; + } + +} \ No newline at end of file diff --git a/src/app/about/about.component.html b/src/app/about/about.component.html index a9f4663..814bc00 100644 --- a/src/app/about/about.component.html +++ b/src/app/about/about.component.html @@ -24,9 +24,17 @@

Also... I love the web because it's the only platform that is truly accepted by everyone, regardless of operating system, country, or government, the web is what ties us all together. - +
+
+
+ Application Use +
+
+ Search for companies currently on the Nasdaq market (start with first 3 letters), click the company name to view past month closing data in graph form. Click the + plus icon to add to watch list or the minus icon to remove from watch list. Again clicking on the company name from the watch list will load + graph data from the IEX API.

- + \ No newline at end of file diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index e975e90..53ac38a 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -6,6 +6,7 @@ import { HomeComponent } from './home/home.component'; import { AboutComponent } from './about/about.component'; import { UserAdminComponent } from './user-admin/user-admin.component'; import { AuthGuard } from './_guards/auth.guard'; +import { RoleGuard } from './_guards/role.guard'; const routes: Routes = [ /* default path sends users to login */ @@ -14,7 +15,7 @@ const routes: Routes = [ { path: 'login', component: LoginComponent }, { path: 'home', component: HomeComponent, canActivate: [AuthGuard] }, { path: 'about', component: AboutComponent, canActivate: [AuthGuard] }, - { path: 'user-admin', component: UserAdminComponent, canActivate: [AuthGuard] } + { path: 'user-admin', component: UserAdminComponent, canActivate: [AuthGuard,RoleGuard] } ]; diff --git a/src/app/app.module.ts b/src/app/app.module.ts index dfe8926..ac6b730 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -16,6 +16,7 @@ import { InMemoryDataService } from './_mockdata/mock-data-nasdaq'; import { EmitcomService } from './_services/emitcom.service'; import { AuthGuard } from './_guards/auth.guard'; +import { RoleGuard } from './_guards/role.guard'; import { AppRoutingModule } from './/app-routing.module'; import { ReactiveFormsModule } from '@angular/forms'; @@ -69,7 +70,8 @@ import { AboutComponent } from './about/about.component'; EmitcomService, MatIconRegistry, - AuthGuard + AuthGuard, + RoleGuard ], bootstrap: [AppComponent] }) diff --git a/src/app/search-view/search-view.component.html b/src/app/search-view/search-view.component.html index f3a39d4..f933d75 100644 --- a/src/app/search-view/search-view.component.html +++ b/src/app/search-view/search-view.component.html @@ -15,6 +15,7 @@ + diff --git a/src/app/search-view/search-view.component.ts b/src/app/search-view/search-view.component.ts index 8b0e073..4546a05 100644 --- a/src/app/search-view/search-view.component.ts +++ b/src/app/search-view/search-view.component.ts @@ -15,6 +15,7 @@ export class SearchViewComponent implements OnInit { searchResults; searchResultLogos; + adminUser = false; constructor( private emitcomService: EmitcomService, @@ -26,6 +27,11 @@ export class SearchViewComponent implements OnInit { ngOnInit() { + /* TODO: The user needs to be a seprate component or just an object that is validated before the page is loaded. */ + if (JSON.parse(localStorage.getItem('currentUser')).role == "B5") { + this.adminUser = true; + } + } searchCompany( searchData ){ diff --git a/src/app/user-admin/user-admin.component.html b/src/app/user-admin/user-admin.component.html index 7a9a9b4..edb2e8d 100644 --- a/src/app/user-admin/user-admin.component.html +++ b/src/app/user-admin/user-admin.component.html @@ -1,3 +1,23 @@ -

- user-admin works! -

+
+ + + + +

Admin

+
+
+ +
+ Oops... + +
+

+ Well it's Wednesday 9/12/2018 and with all the self inflicted scope creep I have run out of time to build this page. +
+
+ On the flip side yay the app is done! +

+
+ +
+
\ No newline at end of file