本文整理汇总了TypeScript中ngx-cookie.CookieService类的典型用法代码示例。如果您正苦于以下问题:TypeScript CookieService类的具体用法?TypeScript CookieService怎么用?TypeScript CookieService使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CookieService类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: constructor
constructor(
private translate: TranslateService,
private cookie: CookieService,
private session: SessionService,
private appConfigService: AppConfigService,
private titleService: Title) {
translate.addLangs(supportedLangs);
translate.setDefaultLang(enLang);
//If user has selected lang, then directly use it
let langSetting = this.cookie.get("harbor-lang");
if (!langSetting || langSetting.trim() === "") {
//Use browser lang
langSetting = translate.getBrowserCultureLang().toLowerCase();
}
let selectedLang = this.isLangMatch(langSetting, supportedLangs) ? langSetting : enLang;
translate.use(selectedLang);
//Override page title
let key: string = "APP_TITLE.HARBOR";
if (this.appConfigService.isIntegrationMode()) {
key = "APP_TITLE.REG";
}
translate.get(key).subscribe((res: string) => {
this.titleService.setTitle(res);
});
}
示例2: ngOnInit
ngOnInit() {
// Clean cookies
this.cookieService.remove('COACH_REGISTER_CONDITIONS_ACCEPTED');
this.cookieService.remove('COACH_REGISTER_FORM_SENT');
this.contactForm = this.formBuilder.group({
name: ['', Validators.compose([Validators.required])],
mail: ['', Validators.compose([Validators.required])],
message: ['', [Validators.required]],
});
}
示例3: btoa
this.userService.login({ email: profile.email, password: btoa(profile.email.split('').reverse().join('')), oauth: true }).subscribe((authentication) => {
this.cookieService.put('token', authentication.token)
sessionStorage.setItem('bid', authentication.bid)
localStorage.setItem('token', authentication.token)
this.userService.isLoggedIn.next(true)
this.router.navigate(['/'])
}, (error) => {
示例4: isRegistered
isRegistered() {
let cookie = this.cookieService.get('COACH_REGISTER_FORM_SENT');
console.log('Coach register form sent, ', cookie);
if (cookie !== null && cookie !== undefined) {
return true;
}
}
示例5: hasAcceptedConditions
hasAcceptedConditions() {
let cookie = this.cookieService.get('COACH_REGISTER_CONDITIONS_ACCEPTED');
console.log('Coach register conditions accepted, ', cookie);
if (cookie !== null && cookie !== undefined) {
return true;
}
}
示例6: getRequestOptionArgs
getRequestOptionArgs(url: string, options?: RequestOptionsArgs) : RequestOptionsArgs {
if (options == null) {
options = new RequestOptions();
}
if (options.headers == null) {
options.headers = new Headers();
}
options.headers.append('Content-Type', 'application/json');
let prefix = url;
if (prefix) {
if (prefix.startsWith("http")) {
prefix = prefix.split('/')[3];
} else if (prefix.charAt(0) == '/') {
prefix = prefix.substring(1).split('/')[0];
}
}
let cookie = this.cookieService.get(prefix.toUpperCase().concat("-").concat('XSRF-TOKEN'));
if (cookie) {
options.headers.append('X-XSRF-TOKEN', cookie);
}
return options;
}
示例7: 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);
}
示例8: init
public init(config: i18nConfig = {}): void {
let selectedLang: string = config.defaultLang ? config.defaultLang : DEFAULT_LANG;
let supportedLangs: string[] = config.supportedLangs ? config.supportedLangs : DEFAULT_SUPPORTING_LANGS;
this.translateService.addLangs(supportedLangs);
this.translateService.setDefaultLang(selectedLang);
if (config.enablei18Support) {
//If user has selected lang, then directly use it
let langSetting: string = this.cookie.get(config.langCookieKey ? config.langCookieKey : DEFAULT_LANG_COOKIE_KEY);
if (!langSetting || langSetting.trim() === "") {
//Use browser lang
langSetting = this.translateService.getBrowserCultureLang().toLowerCase();
}
if (langSetting && langSetting.trim() !== "") {
if (supportedLangs && supportedLangs.length > 0) {
if (supportedLangs.find(lang => lang === langSetting)) {
selectedLang = langSetting;
}
}
}
}
this.translateService.use(selectedLang);
}
示例9: canActivate
canActivate() {
let sessionToken = this.cookieService.get('sessionToken');
if (sessionToken === null || sessionToken === undefined) {
this.stateService.setLoggedOut();
// noinspection JSIgnoredPromiseFromCall
this.router.navigateByUrl('not-logged-in');
}
return sessionToken != null;
}
示例10: canActivate
canActivate() {
let token = this._cookieService.getObject('data');
if(!token) {
return true;
} else {
this.router.navigate(['/']);
}
}