SHARE
TWEET

Untitled

a guest Jun 25th, 2019 47 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. canActivate(
  2.     next: ActivatedRouteSnapshot,
  3.     state: RouterStateSnapshot): Observable<boolean> | Promise<boolean> | boolean {
  4.     let accesstoken: string = next.queryParams.accesstoken;
  5.     if (this.authService.IsAuthenticated) {
  6.  
  7.       let user = this.authService.GetUser();
  8.       let CurrentDate = new Date();
  9.       let date = CurrentDate.getFullYear() + "-" + (CurrentDate.getMonth() + 1) + "-" + CurrentDate.getDate();
  10.  
  11.       if (Date.parse(date) <= Date.parse(user.expire_date)) {
  12.         return true;
  13.       }
  14.     }
  15.       else if (!NOU(accesstoken)) { // In case current registered token is not valid, CheckAccess with new token
  16.         // this.authService.logout();
  17.         this.authService.checkAccess(accesstoken).subscribe(
  18.           data => {
  19.             if (data === true) {
  20.               return true;
  21.             } else {
  22.               this.router.navigate(['/login']);
  23.               return false;
  24.             }
  25.  
  26.           },
  27.           error => {
  28.  
  29.           }
  30.         );
  31.       }
  32.       else {
  33.         this.router.navigate(['/login']);
  34.         return false;
  35.       }
  36.  
  37.   }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top