2018-03-27 10:22:55 +02:00
|
|
|
import { Injectable } from '@angular/core';
|
|
|
|
import { Router,CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot} from '@angular/router';
|
|
|
|
import {Observable} from 'rxjs/Observable';
|
|
|
|
import {Session} from './utils/helper.class';
|
2018-11-01 18:20:05 +01:00
|
|
|
import {LoginErrorCodes} from './utils/guardHelper.class';
|
2018-03-27 10:22:55 +02:00
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class ClaimsCuratorGuard implements CanActivate {
|
|
|
|
|
|
|
|
constructor(private router: Router) {}
|
|
|
|
|
|
|
|
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
|
|
|
|
var user;
|
|
|
|
var role = route.data['role']
|
|
|
|
var loggedIn = false;
|
|
|
|
var isAuthorized = false;
|
2018-11-01 18:20:05 +01:00
|
|
|
var errorCode = LoginErrorCodes.NOT_LOGGIN;
|
2018-03-27 10:22:55 +02:00
|
|
|
|
|
|
|
if(Session.isLoggedIn()){
|
|
|
|
loggedIn = true;
|
2018-06-12 13:15:42 +02:00
|
|
|
if(!Session.isLoggedIn()){
|
2018-03-27 10:22:55 +02:00
|
|
|
loggedIn = false;
|
2018-11-01 18:20:05 +01:00
|
|
|
errorCode = LoginErrorCodes.NOT_VALID;
|
2018-03-27 10:22:55 +02:00
|
|
|
}else {
|
|
|
|
if(Session.isClaimsCurator() || Session.isPortalAdministrator()){
|
|
|
|
isAuthorized =true;
|
|
|
|
}
|
|
|
|
if(!Session.isClaimsCurator() && !Session.isPortalAdministrator()){
|
2018-11-01 18:20:05 +01:00
|
|
|
errorCode = LoginErrorCodes.NOT_ADMIN;
|
2018-03-27 10:22:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}else{
|
2018-11-01 18:20:05 +01:00
|
|
|
errorCode =LoginErrorCodes.NOT_LOGGIN;
|
2018-03-27 10:22:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if(!loggedIn){
|
|
|
|
// this.guardHelper.redirect("/user-info",errorCode,state.url);
|
|
|
|
this.router.navigate(['/user-info'], { queryParams: { "errorCode": errorCode, "redirectUrl": state.url } });
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}else if(!isAuthorized){
|
|
|
|
// this.guardHelper.redirect("/user-info",errorCode,state.url);
|
|
|
|
this.router.navigate(['/user-info'], { queryParams: { "errorCode": errorCode, "redirectUrl": state.url } });
|
|
|
|
return false;
|
|
|
|
}else{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|