mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-12 17:04:57 +00:00
[ADF-4897] delete test-cookie after check (#5164)
* remove cookie test after check * remove cookie test after check * remove cookie test after check * remove cookie test after check * make nullable variable optional in cookie * make nullable variable optional in cookie
This commit is contained in:
parent
313e535b8d
commit
48aca2d30f
@ -22,18 +22,25 @@ import { Injectable } from '@angular/core';
|
||||
})
|
||||
export class CookieService {
|
||||
|
||||
cookieEnabled = false;
|
||||
|
||||
constructor() {
|
||||
// for certain scenarios Chrome may say 'true' but have cookies still disabled
|
||||
if (navigator.cookieEnabled === false) {
|
||||
this.cookieEnabled = false;
|
||||
}
|
||||
|
||||
this.setItem('test-cookie', 'test');
|
||||
this.cookieEnabled = document.cookie.indexOf('test-cookie') >= 0;
|
||||
this.deleteCookie('test-cookie');
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if cookies are enabled.
|
||||
* @returns True if enabled, false otherwise
|
||||
*/
|
||||
isEnabled(): boolean {
|
||||
// for certain scenarios Chrome may say 'true' but have cookies still disabled
|
||||
if (navigator.cookieEnabled === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
document.cookie = 'test-cookie';
|
||||
return document.cookie.indexOf('test-cookie') >= 0;
|
||||
return this.cookieEnabled;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -54,12 +61,20 @@ export class CookieService {
|
||||
* @param expiration Expiration date of the data
|
||||
* @param path "Pathname" to store the cookie
|
||||
*/
|
||||
setItem(key: string, data: string, expiration: Date | null, path: string | null): void {
|
||||
setItem(key: string, data: string, expiration: Date | null = null, path: string | null = null): void {
|
||||
document.cookie = `${key}=${data}` +
|
||||
(expiration ? ';expires=' + expiration.toUTCString() : '') +
|
||||
(path ? `;path=${path}` : ';path=/');
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a cookie Key.
|
||||
* @param key Key to identify the cookie
|
||||
*/
|
||||
deleteCookie(key: string): void {
|
||||
document.cookie = key + '=; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
|
||||
}
|
||||
|
||||
/** Placeholder for testing purposes - do not use. */
|
||||
clear() {
|
||||
/* placeholder for testing purposes */
|
||||
|
Loading…
x
Reference in New Issue
Block a user