2017-12-19 13:53:46 +01:00
|
|
|
import { Injectable } from '@angular/core';
|
2019-01-25 12:18:38 +01:00
|
|
|
import {
|
|
|
|
Router,
|
|
|
|
CanActivate,
|
|
|
|
ActivatedRouteSnapshot,
|
|
|
|
RouterStateSnapshot,
|
2021-07-14 13:19:57 +02:00
|
|
|
UrlTree
|
2019-01-25 12:18:38 +01:00
|
|
|
} from '@angular/router';
|
2019-06-03 15:20:36 +02:00
|
|
|
import {Observable} from 'rxjs';
|
2018-11-01 18:20:05 +01:00
|
|
|
import {LoginErrorCodes} from './utils/guardHelper.class';
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
@Injectable()
|
2019-06-03 15:20:36 +02:00
|
|
|
export class FreeGuard implements CanActivate {
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2019-02-26 16:25:52 +01:00
|
|
|
constructor(private router: Router) {
|
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2019-02-26 16:25:52 +01:00
|
|
|
check(path: string): boolean {
|
|
|
|
const valid = true;
|
|
|
|
if (!valid) {
|
|
|
|
this.router.navigate(['/user-info'], {queryParams: {'errorCode': LoginErrorCodes.NOT_VALID, 'redirectUrl': path}});
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2019-01-25 12:18:38 +01:00
|
|
|
return valid;
|
|
|
|
}
|
|
|
|
|
2021-07-14 13:19:57 +02:00
|
|
|
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
|
2019-01-29 14:03:31 +01:00
|
|
|
return this.check(state.url);
|
2019-01-25 12:18:38 +01:00
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
}
|