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

72 lines
2.1 KiB
TypeScript
Raw Normal View History

2017-07-14 23:33:17 +02:00
import {Injectable} from '@angular/core';
2017-09-03 12:49:59 +02:00
import {ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot} from '@angular/router';
2018-03-07 11:56:50 +01:00
import {LoginService} from '../services/app-user-service/login-service';
2017-05-10 11:04:06 +02:00
@Injectable()
2017-06-08 16:58:28 +02:00
export class LoginGuardSQL implements CanActivate {
2017-05-10 11:04:06 +02:00
2017-09-23 11:53:10 +02:00
constructor(private router: Router,
private loginService: LoginService) {
2017-07-14 23:33:17 +02:00
}
2017-05-10 11:04:06 +02:00
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
2017-10-06 20:11:18 +02:00
if (this.loginService.hasPermission(1)) {
return true;
2017-06-08 16:58:28 +02:00
}
// not logged in so redirect to login page with the return url
2017-07-14 23:33:17 +02:00
this.router.navigate(['/login'], {queryParams: {returnUrl: state.url}});
2017-06-08 16:58:28 +02:00
return false;
}
}
@Injectable()
export class LoginGuardHL implements CanActivate {
2017-09-23 11:53:10 +02:00
constructor(private router: Router,
private loginService: LoginService) {
2017-07-14 23:33:17 +02:00
}
2017-06-08 16:58:28 +02:00
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
2017-10-06 20:11:18 +02:00
if (this.loginService.hasPermission(2)) {
2017-09-23 11:53:10 +02:00
return true;
2017-06-08 16:58:28 +02:00
}
// not logged in so redirect to login page with the return url
2017-07-14 23:33:17 +02:00
this.router.navigate(['/login'], {queryParams: {returnUrl: state.url}});
return false;
}
}
@Injectable()
export class LoginGuardMT implements CanActivate {
2017-09-23 11:53:10 +02:00
constructor(private router: Router,
private loginService: LoginService) {
2017-07-14 23:33:17 +02:00
}
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
2017-10-06 20:11:18 +02:00
if (this.loginService.hasPermission(3)) {
2017-09-23 11:53:10 +02:00
return true;
2017-07-14 23:33:17 +02:00
}
// not logged in so redirect to login page with the return url
this.router.navigate(['/login'], {queryParams: {returnUrl: state.url}});
2017-06-08 16:58:28 +02:00
return false;
}
}
@Injectable()
export class LoginGuardAdmin implements CanActivate {
2017-09-23 11:53:10 +02:00
constructor(private router: Router,
private loginService: LoginService) {
2017-07-14 23:33:17 +02:00
}
2017-06-08 16:58:28 +02:00
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
2017-10-06 20:11:18 +02:00
if (this.loginService.hasPermission(4)) {
2017-09-23 11:53:10 +02:00
return true;
2017-05-10 11:04:06 +02:00
}
// not logged in so redirect to login page with the return url
2017-07-14 23:33:17 +02:00
this.router.navigate(['/login'], {queryParams: {returnUrl: state.url}});
2017-05-10 11:04:06 +02:00
return false;
}
}