guest mode session store update

- allow calls to saveSessionData() but do not actually write if user is guest
- saveSessionData() returns true even if guest, because false is meant to define an error
- You can also use SaveIfRegistered(), this will return false on both saveSessionData() errors AND guest mode;
- if you want to block guests, check for isRegistered() and block the request if it is false
- otherwise this update will allow all tools (including any logins) to work with guest mode, but the stored SessionData will not be persistently saved, and lost when the cleanup timeout hits (default 3 min), or the server is restarted.
This commit is contained in:
zefie
2021-08-09 14:39:11 -04:00
parent fe53525b39
commit 1e0fd20ae6

View File

@@ -94,9 +94,6 @@ class WTVClientSessionData {
this.session_store.cookies[cookie_index] = Object.assign({}, cookie_data); this.session_store.cookies[cookie_index] = Object.assign({}, cookie_data);
// do not write file if user is not registered
if (this.getSessionData('registered')) this.storeSessionData();
return true; return true;
} }
@@ -193,11 +190,16 @@ class WTVClientSessionData {
} }
saveSessionData() { saveSessionData() {
// load data from disk and merge new data if (this.isRegistered()) {
var temp_store = this.session_store; // load data from disk and merge new data
if (this.loadSessionData()) this.session_store = Object.assign(this.session_store, temp_store); var temp_store = this.session_store;
else this.session_store = temp_store; if (this.loadSessionData()) this.session_store = Object.assign(this.session_store, temp_store);
temp_store = null; else this.session_store = temp_store;
temp_store = null;
} else {
// do not write file if user is not registered, return true because this is not an error
return true;
}
try { try {
// only save if file has changed // only save if file has changed
@@ -213,7 +215,7 @@ class WTVClientSessionData {
retrieveSessionData() { retrieveSessionData() {
// alias // alias
this.loadSessionData(); return this.loadSessionData();
} }
storeSessionData() { storeSessionData() {
@@ -222,7 +224,8 @@ class WTVClientSessionData {
} }
SaveIfRegistered() { SaveIfRegistered() {
if (this.isRegistered()) this.saveSessionData(); if (this.isRegistered()) return this.saveSessionData();
return false;
} }
isRegistered() { isRegistered() {