当前位置: 首页>>代码示例>>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;未经允许,请勿转载。