From 1e0fd20ae622f4512fdadc14ca48b5a6a907e325 Mon Sep 17 00:00:00 2001 From: zefie Date: Mon, 9 Aug 2021 14:39:11 -0400 Subject: [PATCH] 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. --- zefie_wtvp_minisrv/WTVClientSessionData.js | 25 ++++++++++++---------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/zefie_wtvp_minisrv/WTVClientSessionData.js b/zefie_wtvp_minisrv/WTVClientSessionData.js index 8450ea95..d44c948d 100644 --- a/zefie_wtvp_minisrv/WTVClientSessionData.js +++ b/zefie_wtvp_minisrv/WTVClientSessionData.js @@ -94,9 +94,6 @@ class WTVClientSessionData { 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; } @@ -193,12 +190,17 @@ class WTVClientSessionData { } saveSessionData() { - // load data from disk and merge new data - var temp_store = this.session_store; - if (this.loadSessionData()) this.session_store = Object.assign(this.session_store, temp_store); - else this.session_store = temp_store; - temp_store = null; - + if (this.isRegistered()) { + // load data from disk and merge new data + var temp_store = this.session_store; + if (this.loadSessionData()) this.session_store = Object.assign(this.session_store, temp_store); + 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 { // only save if file has changed var json_save_data = JSON.stringify(this.session_store); @@ -213,7 +215,7 @@ class WTVClientSessionData { retrieveSessionData() { // alias - this.loadSessionData(); + return this.loadSessionData(); } storeSessionData() { @@ -222,7 +224,8 @@ class WTVClientSessionData { } SaveIfRegistered() { - if (this.isRegistered()) this.saveSessionData(); + if (this.isRegistered()) return this.saveSessionData(); + return false; } isRegistered() {