add admin interface, angular migration

This commit is contained in:
_Bastler
2025-11-09 01:58:54 +01:00
parent ff94ca05ce
commit 1acaf07825
100 changed files with 7129 additions and 50 deletions
+26
View File
@@ -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 });
});
}
}