Revision 55964
Added by Argiro Kokogiannaki almost 5 years ago
loginGuard.guard.ts | ||
---|---|---|
1 |
import { Injectable } from '@angular/core'; |
|
2 |
import {Router, CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, Route, CanLoad} from '@angular/router'; |
|
3 |
import {Observable} from 'rxjs/Observable'; |
|
1 |
import {Injectable} from '@angular/core'; |
|
2 |
import { |
|
3 |
Router, |
|
4 |
CanActivate, |
|
5 |
ActivatedRouteSnapshot, |
|
6 |
RouterStateSnapshot, |
|
7 |
Route, |
|
8 |
CanLoad, |
|
9 |
UrlSegment |
|
10 |
} from '@angular/router'; |
|
11 |
import {Observable} from 'rxjs'; |
|
4 | 12 |
import {Session} from './utils/helper.class'; |
5 | 13 |
import {LoginErrorCodes} from './utils/guardHelper.class'; |
6 | 14 |
|
7 | 15 |
@Injectable() |
8 |
export class LoginGuard implements CanActivate, CanLoad {
|
|
16 |
export class LoginGuard implements CanActivate { |
|
9 | 17 |
|
10 | 18 |
constructor(private router: Router) { |
11 | 19 |
} |
... | ... | |
16 | 24 |
loggedIn = true; |
17 | 25 |
} |
18 | 26 |
if (!loggedIn) { |
19 |
this.router.navigate(['/user-info'], {queryParams: {'errorCode': LoginErrorCodes.NOT_LOGIN, path}}); |
|
27 |
this.router.navigate(['/user-info'], { |
|
28 |
queryParams: { |
|
29 |
'errorCode': LoginErrorCodes.NOT_LOGIN, |
|
30 |
'redirectUrl': path |
|
31 |
} |
|
32 |
}); |
|
20 | 33 |
} |
21 | 34 |
return loggedIn; |
22 | 35 |
} |
... | ... | |
24 | 37 |
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean { |
25 | 38 |
return this.check(state.url); |
26 | 39 |
} |
27 |
|
|
28 |
canLoad(route: Route): Observable<boolean> | Promise<boolean> | boolean { |
|
29 |
return this.check('/' + route.path); |
|
30 |
} |
|
31 | 40 |
} |
Also available in: Unified diff
[Library|Trunk]
Merge into trunk branch angular7 rev 55729