當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript angular2-jwt.tokenNotExpired函數代碼示例

本文整理匯總了TypeScript中angular2-jwt.tokenNotExpired函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript tokenNotExpired函數的具體用法?TypeScript tokenNotExpired怎麽用?TypeScript tokenNotExpired使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了tokenNotExpired函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: protectRoute

 protectRoute(candidate: TraversalCandidate) {
   if (!tokenNotExpired()) {
     this.router.go('/login');
     return Observable.of(false);
   }
   return Observable.of(true);
 }
開發者ID:danielsuter,項目名稱:ng2-camp,代碼行數:7,代碼來源:authGuard.ts

示例2: canActivate

 canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
   if (!tokenNotExpired()) {
     this.router.navigate(['/login']);
     return Observable.of(false);
   }
   return Observable.of(true);
 }
開發者ID:joachimprinzbach,項目名稱:ng2-camp,代碼行數:7,代碼來源:authGuard.ts

示例3: appInjector

export const authorize = (to: ComponentInstruction, from: ComponentInstruction, params: Object = {}) =>
{
  let injector: Injector = appInjector();
  //let router: Router = injector.get(Router);
  let user$: Observable<User> = injector.get(UserService).user$
  let projects$: Observable<Array<Project>> = injector.get(ProjectsService).projects$

  // checks
  let authorized = false;
  let checkToken = tokenNotExpired(null, localStorage.getItem('token'))
  let checkRole$ = user$.map(user => user.role === 'admin' || user.role === params['checkRole'])
  let checkGroup$ = projects$
    .flatMap(project => project)
    .filter(project => project.url === to.urlPath)
    .zip(user$)
    .map(merged => merged[0].groups.map(projectsGroup => merged[1].groups.indexOf(projectsGroup) !== -1))
    .flatMap(merged => merged)

  Observable
    .merge(checkRole$, checkGroup$)
    .filter(check => check === true)
    .subscribe
    (
      (check: boolean) => authorized = check,
      err => console.error // maybe redirect to custom 4xx page here...
    )

  return new Promise((resolve) => resolve(checkToken && authorized))
}
開發者ID:aberenyi,項目名稱:mean-boilerplate-ts,代碼行數:29,代碼來源:authorize.ts

示例4: protectRoute

 protectRoute(candidate: TraversalCandidate) {
   if (tokenNotExpired('auth_token')) {
     return Observable.of(true);
   } else {
     this._router.go('/login');
     return Observable.of(false);
   }
 }
開發者ID:enyachoke,項目名稱:SavannahAcademia,代碼行數:8,代碼來源:auth-guard.ts

示例5: canActivate

  canActivate(next: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
    if (tokenNotExpired()) {
      return true;
    }

    this.router.navigate(['']);
    return false;
  }
開發者ID:BabatundeAlo,項目名稱:ng2_play,代碼行數:8,代碼來源:auth-guard.ts

示例6: loggedIn

 loggedIn(){
   try {
     return tokenNotExpired('id_token');
   } catch(err) {
     this.logout();
     return false;
   }
 }
開發者ID:Cicaults,項目名稱:MEAN-authorization-app,代碼行數:8,代碼來源:auth.service.ts

示例7: canActivate

  canActivate() {
    if (tokenNotExpired()) {
      return true;
    }

    this.router.navigate(['/startPage']);
    return false;
  }
開發者ID:galyniayaroshenko,項目名稱:auth-Angular2-new,代碼行數:8,代碼來源:auth.guard.ts

示例8: handleError

    private handleError(error:any) {
        if(!tokenNotExpired()) {
            console.debug("NOT LOGGED IN")
	    return Observable.throw(error);
        }
        error = error.json() ? {message: error.json().message, status: error.json().status} : error;

        console.error('An error occurred', error);
        return Observable.throw(error);
    }
開發者ID:travisolbrich,項目名稱:scavenger-hunt-ui,代碼行數:10,代碼來源:user.service.ts

示例9: constructor

 constructor(private http: Http, private router: Router, private _userService: UserService,
             private _projectService: ProjectsService)
 {
   this.date = new Date()
   //check whether the user has already logged in...
   if (tokenNotExpired(null, localStorage.getItem('token')))
   {
     this.defaultRedirect()
   }
 }
開發者ID:aberenyi,項目名稱:mean-boilerplate-ts,代碼行數:10,代碼來源:login.component.ts

示例10: canActivate

    canActivate() {
        // Check to see if a user has a valid JWT
        if (tokenNotExpired()) {
            // If they do, return true and allow the user to load the home component
            return true;
        }

        // If not, they redirect them to the login page
        this.router.navigate(['/login']);
        return false;
    }
開發者ID:Vyom131313,項目名稱:SwamiXitiz,代碼行數:11,代碼來源:authGuard.component.ts


注:本文中的angular2-jwt.tokenNotExpired函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。