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


TypeScript angular-2-local-storage.LocalStorageService類代碼示例

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


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

示例1: canActivate

    canActivate(): Observable<boolean> | boolean {
        //var tempRoute = state.url;

        if (this.localStorageService.get("accessToken")) {

            var user_name = this.localStorageService.get<string>("userEmail");
            var access_token = this.localStorageService.get<string>("accessToken");
            var refresh_token = this.localStorageService.get<string>("refreshToken");
            //Check Validate Token 
            if (this.AuthService.checkValidateToken(access_token)) {
                //Exist Token
                //Check Time Token
                var datetime = (Date.now() / 1000);
                var expires_time = this.localStorageService.get<number>("expiresTime");
                var remain_time = expires_time - datetime;

                if (remain_time > -1) {
                    //Refresh Token
                    if (remain_time < 600) {

                        //api to refresh Token
                        return this.AuthService.refreshToken(user_name, access_token, refresh_token).map(response => {
                            if (response) {
                                this.localStorageService.set("accessToken", response.access_token);
                                this.localStorageService.set("refreshToken", response.refresh_token);
                                this.localStorageService.set("expiresTime", (Date.now() / 1000) + response.expires_in);
                                console.log("refresh token");
                                this.AuthService.checkRoleForRedirect(/*tempRoute*/);
                                return true;
                            } else {
                                response => {
                                    console.log("Try to Login again");
                                }
                            }
                        })

                    } else {
                        //console.log("exist token");
                        //check user data
                        this.AuthService.checkRoleForRedirect(/*tempRoute*/);
                        return true;
                    }
                } else {
                    console.log("expire token");
                    this.navCtrl.push(LoginComponent);
                }

            } else {
                //Wrong Token
                console.log("wrong token");
                this.navCtrl.push(LoginComponent);

            }
        } else {
            console.log("not have token");
            this.navCtrl.push(LoginComponent);
        }

    }
開發者ID:uopeydel,項目名稱:game_project,代碼行數:59,代碼來源:auth.guard.ts

示例2:

					response => {
						var content = response.json().content,
							user = content[0];

						this.localStorageService.set("userFirstName", user.firstName);
						this.localStorageService.set("userSurname", user.surname);
						this.localStorageService.set("userId", user._id);
						this.localStorageService.set("userRole", user.role);

						window.location.href = '//' + window.location.host;
					});
開發者ID:gmiriam,項目名稱:frontend,代碼行數:11,代碼來源:landing.component.ts

示例3:

 return this.AuthService.refreshToken(user_name, access_token, refresh_token).map(response => {
     if (response) {
         this.localStorageService.set("accessToken", response.access_token);
         this.localStorageService.set("refreshToken", response.refresh_token);
         this.localStorageService.set("expiresTime", (Date.now() / 1000) + response.expires_in);
         console.log("refresh token");
         this.AuthService.checkRoleForRedirect(/*tempRoute*/);
         return true;
     } else {
         response => {
             console.log("Try to Login again");
         }
     }
 })
開發者ID:uopeydel,項目名稱:game_project,代碼行數:14,代碼來源:auth.guard.ts

示例4: getCurrentConnectionProfile

 getCurrentConnectionProfile(): string {
     let result = this.localStorageService.get<string>('currentConnectionProfile');
     if (result === null) {
         result = '$default';
     }
     return result;
 }
開發者ID:GitWhiskey,項目名稱:composer,代碼行數:7,代碼來源:connectionprofile.service.ts

示例5: Error

 .then(() => {
     if (this.localStorageService.clearAll()) {
         this.zone.runOutsideAngular(() => {
             location.reload();
         });
     } else {
         throw new Error('Failed to clear local storage');
     }
 });
開發者ID:bloonbullet,項目名稱:composer,代碼行數:9,代碼來源:version-check.component.ts

示例6: clearLocalStorage

 public clearLocalStorage() {
     indexedDB.deleteDatabase('_pouch_Composer');
     if (this.localStorageService.clearAll()) {
         this.zone.runOutsideAngular(() => {
             location.reload();
         });
     } else {
         throw new Error('Failed to clear local storage');
     }
 }
開發者ID:marlonprudente,項目名稱:composer,代碼行數:10,代碼來源:version-check.component.ts

示例7: intercept

  intercept(req: HttpRequest<any>, next: HttpHandler) {
    const authToken = this._localStorageService.get<string>(AuthConstants.getAuthTokenKey());
    const authReq = req.clone({
      setHeaders: {
        'Content-Type': 'application/json; charset=utf-8',
        'Accept': 'application/json',
        'Authorization': authToken,
      },
    });

    return next.handle(authReq);
  }
開發者ID:jsnmgpnty,項目名稱:pngo-fe-test,代碼行數:12,代碼來源:authInterceptor.ts

示例8: clearLocalStorage

    public clearLocalStorage(): Promise<boolean> {
        if (this.localStorageService.clearAll()) {
            return this.router.navigateByUrl('/')
            .then((result) => {

                if (result) {
                    window.open('/', '_self');
                }

                return result;

            });
        } else {
            throw new Error('Failed to clear local storage');
        }
    }
開發者ID:GitWhiskey,項目名稱:composer,代碼行數:16,代碼來源:version-check.component.ts

示例9: logout

    logout(access_token: string, refresh_token: string): Observable<any> {

        let dataObj = {
            Access: access_token,
            Refresh: refresh_token
        }

        const url = this._config.apiAuthURL + "api/v1/ManagementTokens/ClearTokens";
        let headers = new Headers({ 'Content-Type': 'application/json' });
        let options = new RequestOptions({ headers: headers });

        this.sub = this.http.post(url, dataObj, options).catch(this.handleError);

        // clear token remove user from local storage to log user out
        this.localStorageService.clearAll();

        return this.sub;
    }
開發者ID:uopeydel,項目名稱:game_project,代碼行數:18,代碼來源:auth.service.ts


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