Guest User

Untitled

a guest
Nov 22nd, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. import { Injectable } from '@angular/core';
  2. import { Location } from '@angular/common';
  3. import { CanActivate, RouterStateSnapshot, ActivatedRouteSnapshot } from '@angular/router';
  4. import { EidCookieService } from '../services/eid/eIdCookie.service';
  5. import URL = require('url-parse');
  6. import { Document } from '../components/document/document';
  7.  
  8. @Injectable()
  9. export class EidGuard implements CanActivate {
  10.  
  11. constructor(private eIdCookieService: EidCookieService, private location: Location) { }
  12.  
  13. private getEidLoginRedirectUrl(currentUrl) {
  14. const protocol = new URL(currentUrl).protocol;
  15. switch (process.env.NODE_ENV) {
  16. case 'PROD':
  17. case 'production':
  18. case 'build':
  19. return `http://sso-portal.xxxxxxx.com`;
  20. case 'TEST':
  21. case 'testing':
  22. return `http://sso-portal-test.xxxxxxx.com`;
  23. default:
  24. return `http://sso-portal-dev.xxxxxxx.com`;
  25. }
  26. }
  27.  
  28. canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
  29. if (!this.eIdCookieService.checkCookie(('auth-cookie'))) {
  30. const redirectUrl = this.getEidLoginRedirectUrl(state.url);
  31. this.location.go(redirectUrl);
  32. return false;
  33. }
  34. return true;
  35. }
  36.  
  37. canActivateChild(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
  38. return this.canActivate(route, state);
  39. }
  40. }
Add Comment
Please, Sign In to add comment