Centralize session options and adjust cookies
Configure session cookie options centrally in initRouter and remove per-login MaxAge handling. Deleted SetMaxAge helper and its use in the login flow; session.Options are now applied once using basePath with HttpOnly and SameSite defaults, and MaxAge is set only when the stored setting is available and >0. Also make CookieManager.setCookie treat exdays as optional (only add expires when provided) and stop using a hardcoded 150-day expiry for the lang cookie in the JS language manager. Co-Authored-By: Alireza Ahmadi <alireza7@gmail.com>
This commit is contained in:
@@ -651,10 +651,13 @@ class CookieManager {
|
||||
}
|
||||
|
||||
static setCookie(cname, cvalue, exdays) {
|
||||
const d = new Date();
|
||||
d.setTime(d.getTime() + exdays * 24 * 60 * 60 * 1000);
|
||||
let expires = 'expires=' + d.toUTCString();
|
||||
document.cookie = cname + '=' + encodeURIComponent(cvalue) + ';' + expires + ';path=/';
|
||||
let expires = '';
|
||||
if (exdays) {
|
||||
const d = new Date();
|
||||
d.setTime(d.getTime() + exdays * 24 * 60 * 60 * 1000);
|
||||
expires = 'expires=' + d.toUTCString() + ';';
|
||||
}
|
||||
document.cookie = cname + '=' + encodeURIComponent(cvalue) + ';' + expires + 'path=/';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -813,13 +816,13 @@ class LanguageManager {
|
||||
});
|
||||
|
||||
if (LanguageManager.isSupportLanguage(lang)) {
|
||||
CookieManager.setCookie("lang", lang, 150);
|
||||
CookieManager.setCookie("lang", lang);
|
||||
} else {
|
||||
CookieManager.setCookie("lang", "en-US", 150);
|
||||
CookieManager.setCookie("lang", "en-US");
|
||||
window.location.reload();
|
||||
}
|
||||
} else {
|
||||
CookieManager.setCookie("lang", "en-US", 150);
|
||||
CookieManager.setCookie("lang", "en-US");
|
||||
window.location.reload();
|
||||
}
|
||||
}
|
||||
@@ -832,7 +835,7 @@ class LanguageManager {
|
||||
language = "en-US";
|
||||
}
|
||||
|
||||
CookieManager.setCookie("lang", language, 150);
|
||||
CookieManager.setCookie("lang", language);
|
||||
window.location.reload();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user