当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript ng2-cookies.Cookie类代码示例

本文整理汇总了TypeScript中ng2-cookies.Cookie的典型用法代码示例。如果您正苦于以下问题:TypeScript Cookie类的具体用法?TypeScript Cookie怎么用?TypeScript Cookie使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Cookie类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: resetUser

 resetUser(): void {
     Cookie.delete('crsftoken');
     this.removeFromStorage('bhmc_token');
     this._currentUser = new User();
     this.currentUserSource.next(this._currentUser);
     this.saveToStorage('bhmc_user', JSON.stringify(this._currentUser));
     this.errorHandler.clearUserContext();
 }
开发者ID:finleysg,项目名称:bhmc,代码行数:8,代码来源:authentication.service.ts

示例2: canActivate

 canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
     // 存储appToken到session
     if (!Cookie.get(CommonConfig.AUTH_TOKEN)) {
         this.router.navigate(['/user/login']);
         return false;
     } else {
         return true;
     }
 }
开发者ID:luoqg,项目名称:wikift,代码行数:9,代码来源:auth.guard.ts

示例3: createHeaders

 private createHeaders(contentType: string): Headers {
     let headers = new Headers({'Content-Type': contentType});
     let token = localStorage.getItem('bhmc_token');
     if (!token) {
         token = sessionStorage.getItem('bhmc_token');
     }
     if (token) {
         headers.append('Authorization', 'Token ' + token);
     }
     // This cookie is added to responses by Django
     let csrf = Cookie.get('csrftoken');
     if (csrf) {
         headers.append('X-CSRFToken', csrf);
     }
     return headers;
 }
开发者ID:finleysg,项目名称:bhmc,代码行数:16,代码来源:bhmc-data.service.ts

示例4: login

 /**
  * 登录
  */
 login(param: LoginParamModel) {
     console.log(`用户 ${param.username} 正在登录...`);
     Cookie.set(CommonConfig.AUTH_USER_NAME, param.username);
     const params = HttpUtils.getParams();
     params.append('username', param.username);
     params.append('password', param.password);
     params.append('grant_type', CommonConfig.AUTH_GRANT_TYPE);
     params.append('client_id', CommonConfig.AUTH_CLIENT_ID);
     const options = HttpUtils.getDefaultRequestOptionsByClient();
     options.params = params;
     return this.http.post(ApiConfig.AUTHORIZATION_API, param.toJson(), options)
         .map(res => res.json())
         .subscribe(
         data => {
             this.saveToken(data);
             return true;
         },
         err => {
             CookieUtils.clearBy(CommonConfig.AUTH_USER_NAME);
             this.toastyService.error('登录失败, 请检查您的用户名或密码');
             return false;
         });
 }
开发者ID:luoqg,项目名称:wikift,代码行数:26,代码来源:user.service.ts

示例5: getUser

 public static getUser() {
     const data = Cookie.get(CommonConfig.AUTH_USER_INFO);
     if (data.length > 0) {
         return JSON.parse(data);
     }
 }
开发者ID:luoqg,项目名称:wikift,代码行数:6,代码来源:cookie.util.ts

示例6: logout

 logout() {
   Cookie.delete('access_token');
   this._router.navigate(['/login']);
 }
开发者ID:eugenp,项目名称:spring-security-oauth,代码行数:4,代码来源:app.service.ts

示例7: checkCredentials

 checkCredentials(){
   if (!Cookie.check('access_token')){
       this._router.navigate(['/login']);
   }
 } 
开发者ID:eugenp,项目名称:spring-security-oauth,代码行数:5,代码来源:app.service.ts

示例8: getResource

 getResource(resourceUrl) : Observable<Foo>{
   var headers = new Headers({'Content-type': 'application/x-www-form-urlencoded; charset=utf-8', 'Authorization': 'Bearer '+Cookie.get('access_token')});
   var options = new RequestOptions({ headers: headers });
   return this._http.get(resourceUrl, options)
                  .map((res:Response) => res.json())
                  .catch((error:any) => Observable.throw(error.json().error || 'Server error'));
 }
开发者ID:eugenp,项目名称:spring-security-oauth,代码行数:7,代码来源:app.service.ts

示例9: saveToken

 saveToken(token){
   var expireDate = new Date().getTime() + (1000 * token.expires_in);
   Cookie.set("access_token", token.access_token, expireDate);
   console.log('Obtained Access token');
   this._router.navigate(['/']);
 }
开发者ID:eugenp,项目名称:spring-security-oauth,代码行数:6,代码来源:app.service.ts

示例10: onLanguageChange

 onLanguageChange(language: any) {
     this.translate.use(language.locale);
     Cookie.set(AppConfig.languageCookieName, language.locale, null, "/");
     this.languageService.onLanguageSet(language.locale);
 }
开发者ID:jacekcgi,项目名称:planeRepo,代码行数:5,代码来源:language.component.ts


注:本文中的ng2-cookies.Cookie类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。