Project

General

Profile

1 51526 argiro.kok
import { Injectable } from '@angular/core';
2 54750 konstantin
import {Router, CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, CanLoad, Route} from '@angular/router';
3 51526 argiro.kok
import {Observable}       from 'rxjs/Observable';
4
import {Session} from './utils/helper.class';
5 53612 konstantin
import {LoginErrorCodes} from './utils/guardHelper.class';
6 51526 argiro.kok
7
@Injectable()
8 54750 konstantin
export class ClaimsCuratorGuard implements CanActivate, CanLoad {
9 51526 argiro.kok
10
  constructor(private router: Router) {}
11
12 54750 konstantin
  check(path: string)  : boolean{
13
    //var user;
14
    //var role = route.data['role']
15
    let loggedIn = false;
16
    let isAuthorized = false;
17
    let errorCode = LoginErrorCodes.NOT_LOGIN;
18 51526 argiro.kok
19
    if(Session.isLoggedIn()){
20
      loggedIn = true;
21 54750 konstantin
      if(Session.isClaimsCurator() || Session.isPortalAdministrator()){
22
        isAuthorized = true;
23
      }
24
      else {
25
        errorCode = LoginErrorCodes.NOT_ADMIN;
26
      }
27 51526 argiro.kok
    }
28 54750 konstantin
    if(!loggedIn || !isAuthorized){
29 51526 argiro.kok
      // this.guardHelper.redirect("/user-info",errorCode,state.url);
30 54750 konstantin
      this.router.navigate(['/user-info'], {queryParams: {"errorCode": errorCode, "redirectUrl": path}});
31 51526 argiro.kok
    }
32 54750 konstantin
    return loggedIn && isAuthorized;
33 51526 argiro.kok
  }
34 54750 konstantin
35
  canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
36
    return this.check(state.url);
37
  }
38
39
  canLoad(route: Route): Observable<boolean> | Promise<boolean> | boolean {
40
    return this.check('/' + route.path);
41
  }
42 51526 argiro.kok
}