1 |
54479
|
myrto.kouk
|
|
2 |
|
|
import {Injectable} from '@angular/core';
|
3 |
|
|
import {ActivatedRouteSnapshot, CanActivate, CanLoad, Router, RouterStateSnapshot} from '@angular/router';
|
4 |
|
|
import {AuthenticationService} from './authentication.service';
|
5 |
|
|
import { getCookie } from '../domain/utils';
|
6 |
|
|
|
7 |
|
|
@Injectable ()
|
8 |
|
|
export class AuthGuardService implements CanActivate, CanLoad {
|
9 |
|
|
|
10 |
|
|
constructor (private authenticationService: AuthenticationService, private router: Router) {}
|
11 |
|
|
|
12 |
|
|
canActivate (route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
|
13 |
61435
|
spyroukon
|
if ( this.authenticationService.getIsUserLoggedIn() ) { return true; }
|
14 |
54479
|
myrto.kouk
|
|
15 |
|
|
/* If no cookie was found, clear the app's session.
|
16 |
|
|
The user may have logged out using another OpenAIRE portal */
|
17 |
|
|
sessionStorage.clear();
|
18 |
|
|
|
19 |
|
|
// Store the attempted URL for redirecting
|
20 |
|
|
sessionStorage.setItem('state.location', state.url);
|
21 |
|
|
|
22 |
|
|
// If we decide that in this case we will send the user back to the aai
|
23 |
|
|
// this.authenticationService.redirectUrl = state.url;
|
24 |
|
|
// this.authenticationService.loginWithState();
|
25 |
|
|
|
26 |
58110
|
stefania.m
|
this.router.navigate(['/home']);
|
27 |
54479
|
myrto.kouk
|
|
28 |
|
|
return false;
|
29 |
|
|
}
|
30 |
|
|
|
31 |
|
|
canLoad () {
|
32 |
|
|
|
33 |
|
|
if (this.authenticationService.getUserRole() &&
|
34 |
61426
|
spyroukon
|
(this.authenticationService.getUserRole().includes('SUPER_ADMINISTRATOR') ||
|
35 |
|
|
this.authenticationService.getUserRole().includes('CONTENT_PROVIDER_DASHBOARD_ADMINISTRATOR')) ) {
|
36 |
54747
|
myrto.kouk
|
console.log('Admin recognized');
|
37 |
54479
|
myrto.kouk
|
return true;
|
38 |
|
|
}
|
39 |
|
|
|
40 |
58110
|
stefania.m
|
this.router.navigate(['/home']);
|
41 |
54479
|
myrto.kouk
|
|
42 |
|
|
return false;
|
43 |
|
|
}
|
44 |
|
|
}
|