opt-cc/static/src/app/login/login.guard.ts

72 lines
2.1 KiB
TypeScript

import {Injectable} from '@angular/core';
import {ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot} from '@angular/router';
import {LoginService} from '../services/app-user-service/login-service';
@Injectable()
export class LoginGuardSQL implements CanActivate {
constructor(private router: Router,
private loginService: LoginService) {
}
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
if (this.loginService.hasPermission(1)) {
return true;
}
// not logged in so redirect to login page with the return url
this.router.navigate(['/login'], {queryParams: {returnUrl: state.url}});
return false;
}
}
@Injectable()
export class LoginGuardHL implements CanActivate {
constructor(private router: Router,
private loginService: LoginService) {
}
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
if (this.loginService.hasPermission(2)) {
return true;
}
// not logged in so redirect to login page with the return url
this.router.navigate(['/login'], {queryParams: {returnUrl: state.url}});
return false;
}
}
@Injectable()
export class LoginGuardMT implements CanActivate {
constructor(private router: Router,
private loginService: LoginService) {
}
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
if (this.loginService.hasPermission(3)) {
return true;
}
// not logged in so redirect to login page with the return url
this.router.navigate(['/login'], {queryParams: {returnUrl: state.url}});
return false;
}
}
@Injectable()
export class LoginGuardAdmin implements CanActivate {
constructor(private router: Router,
private loginService: LoginService) {
}
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
if (this.loginService.hasPermission(4)) {
return true;
}
// not logged in so redirect to login page with the return url
this.router.navigate(['/login'], {queryParams: {returnUrl: state.url}});
return false;
}
}