Project

General

Profile

1
import { Injectable } from '@angular/core';
2
import {
3
  Router,
4
  CanActivate,
5
  ActivatedRouteSnapshot,
6
  RouterStateSnapshot,
7
} from '@angular/router';
8
import {Observable} from 'rxjs';
9
import {LoginErrorCodes} from './utils/guardHelper.class';
10

    
11
@Injectable()
12
export class FreeGuard implements CanActivate {
13

    
14
  constructor(private router: Router) {
15
  }
16

    
17
  check(path: string): boolean {
18
    const valid = true;
19
    if (!valid) {
20
      this.router.navigate(['/user-info'], {queryParams: {'errorCode': LoginErrorCodes.NOT_VALID, 'redirectUrl': path}});
21
    }
22
    return valid;
23
  }
24

    
25
  canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
26
    return this.check(state.url);
27
  }
28

    
29
}
(3-3/11)