• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript angular-2-local-storage.LocalStorageService类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript angular.IAugmentedJQuery类代码示例发布时间:2022-05-28
下一篇:
TypeScript angular.toJson函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap