File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11{
22 "name" : " srt" ,
3- "version" : " 1.4.0dev0 " ,
3+ "version" : " 1.4.0dev1 " ,
44 "license" : " MIT" ,
55 "scripts" : {
66 "ng" : " ng" ,
Original file line number Diff line number Diff line change @@ -59,6 +59,27 @@ export class AuthGuard implements CanActivate {
5959 }
6060 }
6161
62+ /**
63+ * check if user is admin
64+ */
65+ checkAdmin ( ) : boolean {
66+ if ( this . isGSAAdmin ) {
67+ return true ;
68+ } else {
69+ this . authService . checkToken ( ) . subscribe (
70+ ( data ) => {
71+ this . isGSAAdmin = data . isGSAAdmin ;
72+ if ( data . isGSAAdmin ) {
73+ return true ;
74+ } else {
75+ return false ;
76+ }
77+ } ) ;
78+ }
79+ }
80+
81+
82+
6283
6384 // Kailun's new add
6485
Original file line number Diff line number Diff line change 11import { Component , OnInit } from '@angular/core' ;
22import { AuthGuard } from '../../auth-guard.service' ;
3-
43import { Router } from '@angular/router' ;
54import { BaseComponent } from '../../base.component' ;
65import { Title } from '@angular/platform-browser' ;
@@ -16,6 +15,8 @@ export class HomeComponent extends BaseComponent implements OnInit {
1615 currentID : string ;
1716 isGSAAdmin = false ;
1817
18+ private adminCheckTimes : number = 0 ;
19+
1920 /* CONSTRUCTORS */
2021
2122 /**
@@ -36,12 +37,32 @@ export class HomeComponent extends BaseComponent implements OnInit {
3637 * lifecycle
3738 */
3839 ngOnInit ( ) {
39- this . isGSAAdmin = this . auth . isGSAAdmin ;
40+ this . loadAdminComponents ( ) ;
4041 this . currentID = localStorage . getItem ( 'id' ) ;
4142 this . pageName = 'SRT Home Page' ;
4243 super . ngOnInit ( ) ;
44+
45+ this . checkAdmin ( ) ;
4346 }
4447
48+ ngOnChanges ( ) {
49+ }
50+
51+ loadAdminComponents ( ) {
52+ this . isGSAAdmin = this . auth . checkAdmin ( ) ;
53+ }
4554
55+ checkAdmin ( ) {
56+ const interval = setInterval ( ( ) => {
57+ this . loadAdminComponents ( ) ;
58+
59+ if ( this . adminCheckTimes > 1 ) {
60+ clearInterval ( interval ) ;
61+ }
62+ this . adminCheckTimes ++ ;
63+
64+ } , 2000 ) ;
65+
66+ }
4667
4768}
You can’t perform that action at this time.
0 commit comments