當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。