add admin interface, angular migration
This commit is contained in:
@@ -104,4 +104,30 @@ export class AnonymousGuard implements CanActivate {
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class AdminGuard implements CanActivate {
|
||||
constructor(private authService: AuthService, private router: Router) { }
|
||||
|
||||
canActivate(next: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
|
||||
const that = this;
|
||||
return this.authService.getAuth().then((data: any) => {
|
||||
if (!data.authenticated) {
|
||||
return that.router.navigateByUrl(that.router.parseUrl('/login?target=' + encodeURIComponent(state.url)), { skipLocationChange: true, replaceUrl: true });
|
||||
}
|
||||
|
||||
// Check if user has ROLE_ADMIN
|
||||
if (data.authorities && data.authorities.some((auth: any) => auth.authority === 'ROLE_ADMIN')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// User is authenticated but not an admin
|
||||
return that.router.navigateByUrl('/account/info');
|
||||
}).catch(function (error) {
|
||||
return that.router.navigateByUrl(that.router.parseUrl('/unavailable?target=' + encodeURIComponent(state.url)), { skipLocationChange: true });
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user