Project

General

Profile

1

    
2
import {Injectable} from '@angular/core';
3
import {ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot} from '@angular/router';
4
import {AuthenticationService} from './authentication.service';
5
import { getCookie } from '../domain/utils';
6
import {apiUrl} from "../domain/tempAPI";
7

    
8
@Injectable ()
9
export class AuthGuardService implements CanActivate {
10

    
11
//  private oidc_endpoint : string = process.env.OIDC_ENDPOINT;
12
  /*private loginUrl : string = `${apiUrl}/openid_connect_login`;*/
13
  private loginUrl = process.env.AAI_ENDPOINT;
14

    
15
  constructor (private authenticationService: AuthenticationService, private router: Router) {}
16

    
17
  canActivate (route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
18

    
19
    if ( this.authenticationService.getIsUserLoggedIn() ) { return true; }
20

    
21
    if ( getCookie('currentUser') != null ) { return true; }
22

    
23
    // Store the attempted URL for redirecting
24
    sessionStorage.setItem("state.location",state.url);
25

    
26
    // Navigate to the login page via the API
27
    window.location.href = this.loginUrl;
28

    
29
    return false;
30
  }
31
}
(1-1/8)