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


TypeScript ng2-ui-auth.AuthService類代碼示例

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


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

示例1: intercept

  intercept(
    request: HttpRequest<any>,
    next: HttpHandler
  ): Observable<HttpEvent<any>> {
    if (!this.auth) {
      this.auth = this.injector.get(AuthService);
    }

    if (this.auth.isAuthenticated()) {
      request = request.clone({
        setHeaders: {
          'X-Auth-Token': this.auth.getToken()
        }
      });
    }

    // Add CSRF token for the Play CSRF filter
    const token = this.cookieService.get('PLAY_CSRF_TOKEN');
    if (token) {
      // Play looks for a token with the name Csrf-Token
      // https://www.playframework.com/documentation/2.4.x/ScalaCsrf
      request = request.clone({
        setHeaders: {
          'Csrf-Token': token
        }
      });
    }

    return next.handle(request);
  }
開發者ID:epot,項目名稱:Gifter,代碼行數:30,代碼來源:token-interceptor.ts

示例2: logout

    logout(): void {
        // clear token remove user from local storage to log user out

        this.auth.logout()
            .subscribe({
                complete: () => {
                    this.localstorage.clear('client_id');
                    this.user = null;
                    //                    UIService.notify('You have been logged out', 'info');
                    //                    $state.go('login');
                }
            });
        this.auth.removeToken();
        this.router.navigateByUrl('/login');
    }
開發者ID:megamtech,項目名稱:angular-php-framework,代碼行數:15,代碼來源:authentication.service.ts

示例3:

 .map((response: Response) => {
     let token = response.json() && response.json().token;
     console.log(token);
     if (typeof token !== 'undefined') {
         this.auth.setToken(token);
         if (this.auth.isAuthenticated() === true) {
             this.getUserDetails();
             if (this.user['default_client_id'] !== null) {
                 this.setDefaultClientId(this.user['default_client_id']);
             }
             return true;
         }
     }
     return false;
 });
開發者ID:megamtech,項目名稱:angular-php-framework,代碼行數:15,代碼來源:authentication.service.ts

示例4: isClientRole

 isClientRole() {
     if (this.auth.getPayload().data.role_id == 10) {
         return true;
     } else {
         return false;
     }
 }
開發者ID:megamtech,項目名稱:angular-php-framework,代碼行數:7,代碼來源:authentication.service.ts

示例5: loginWithGoogle

 loginWithGoogle() {
     this.auth.authenticate('google')
         .subscribe({
             error: (err: any) => this.eh.handleError(err),
             complete: () => this.router.navigateByUrl('main')
         });
 }
開發者ID:royipressburger,項目名稱:ng2-ui-auth-example,代碼行數:7,代碼來源:login.component.ts

示例6: login

 login(loginData: ILoginData) {
     this.auth.login(loginData)
         .subscribe({
             error: (err: any) => this.eh.handleError(err),
             complete: () => this.router.navigateByUrl('main')
         });
 }
開發者ID:royipressburger,項目名稱:ng2-ui-auth-example,代碼行數:7,代碼來源:login.component.ts

示例7: logout

 logout() {
     this.auth.logout()
         .subscribe({
             error: (err: any) => this.eh.handleError(err),
             complete: () => this.router.navigateByUrl('login')
         });
 }
開發者ID:royipressburger,項目名稱:ng2-ui-auth-example,代碼行數:7,代碼來源:main.component.ts

示例8: getUserDetails

 getUserDetails() {
     var userDetails = this.auth.getPayload();
     if (typeof userDetails !== 'undefined') {
         this.user = userDetails.data;
     } else {
         return false;
     }
 }
開發者ID:megamtech,項目名稱:angular-php-framework,代碼行數:8,代碼來源:authentication.service.ts

示例9: canActivate

 canActivate(next: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
   if (this.auth.isAuthenticated()) {
     return true;
   }
   console.log('unauthenticated navigating to login');
   this.router.navigateByUrl('/login');
   return false;
 }
開發者ID:epot,項目名稱:Gifter,代碼行數:8,代碼來源:auth-guard.service.ts

示例10: link

 link() {
     this.auth.link('google')
         .subscribe({
             error: (err: any) => this.eh.handleError(err),
             complete: () => {
                 this.expiration = this.auth.getExpirationDate();
                 this.user = this.auth.getPayload();
             }
         });
 }
開發者ID:royipressburger,項目名稱:ng2-ui-auth-example,代碼行數:10,代碼來源:main.component.ts


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