hopefully fix things this time

This commit is contained in:
zefie
2022-02-10 00:54:40 -05:00
parent db1b03fd99
commit af34d66488
3 changed files with 25 additions and 23 deletions

View File

@@ -51,7 +51,7 @@ class WTVClientSessionData {
this.loginWhitelist = Object.assign([], this.lockdownWhitelist); // clone lockdown whitelist into login whitelist this.loginWhitelist = Object.assign([], this.lockdownWhitelist); // clone lockdown whitelist into login whitelist
this.loginWhitelist.push("wtv-head-waiter:/choose-user"); this.loginWhitelist.push("wtv-head-waiter:/choose-user");
this.loginWhitelist.push("wtv-head-waiter:/password"); this.loginWhitelist.push("wtv-head-waiter:/password");
this.mailstore = new WTVMail(minisrv_config, ssid, this); this.mailstore = new WTVMail(minisrv_config, this);
} }

View File

@@ -21,7 +21,7 @@ class WTVMail {
msgFileExt = ".zmsg"; msgFileExt = ".zmsg";
trashMailboxName = "Trash"; trashMailboxName = "Trash";
constructor(minisrv_config, ssid, wtvclient) { constructor(minisrv_config, wtvclient) {
if (!minisrv_config) throw ("minisrv_config required"); if (!minisrv_config) throw ("minisrv_config required");
var WTVShared = require('./WTVShared.js')['WTVShared']; var WTVShared = require('./WTVShared.js')['WTVShared'];
var WTVMime = require('./WTVMime.js'); var WTVMime = require('./WTVMime.js');
@@ -31,7 +31,8 @@ class WTVMail {
this.wtvmime = new WTVMime(minisrv_config); this.wtvmime = new WTVMime(minisrv_config);
this.wtvclient = wtvclient; this.wtvclient = wtvclient;
this.is_guest = !this.wtvclient.isRegistered(); this.is_guest = !this.wtvclient.isRegistered();
this.ssid = ssid; this.ssid = wtvclient.ssid;
console.log(this.ssid);
this.unread_mail = this.wtvclient.getSessionData("subscriber_unread_mail") ? this.wtvclient.getSessionData("subscriber_unread_mail") : 0; this.unread_mail = this.wtvclient.getSessionData("subscriber_unread_mail") ? this.wtvclient.getSessionData("subscriber_unread_mail") : 0;
this.mailboxes = [ this.mailboxes = [
// referenced by id, so order is important! // referenced by id, so order is important!
@@ -291,22 +292,25 @@ class WTVMail {
} }
checkUserExists(username, directory = null) { checkUserExists(username, directory = null) {
// returns the user's username if true, false if not // returns the user's ssid, and user_id and userid in an array if true, false if not
var username_match = false; var username_match = false;
var search_dir = this.session_store_dir; var search_dir = this.minisrv_config.config.SessionStore;
var return_val = false; var return_val = false;
var self = this; var self = this;
if (directory) search_dir = directory; if (directory) search_dir = directory;
this.fs.readdirSync(search_dir).forEach(file => { this.fs.readdirSync(search_dir).forEach(file => {
if (self.fs.lstatSync(search_dir + self.path.sep + file).isDirectory()) { if (self.fs.lstatSync(search_dir + self.path.sep + file).isDirectory() && !return_val) {
return self.checkUserExists(username, search_dir + self.path.sep + file); return_val = self.checkUserExists(username, search_dir + self.path.sep + file);
} }
if (!file.match(/.*\.json/ig)) return; if (!file.match(/.*\.json/ig)) return;
if (username_match) return; if (username_match) return;
try { try {
var temp_session_data_file = this.fs.readFileSync(search_dir + this.path.sep + file, 'Utf8'); var temp_session_data_file = self.fs.readFileSync(search_dir + self.path.sep + file, 'Utf8');
var temp_session_data = JSON.parse(temp_session_data_file); var temp_session_data = JSON.parse(temp_session_data_file);
if (temp_session_data.subscriber_username.toLowerCase() == username.toLowerCase()) return_val = temp_session_data.subscriber_username; if (temp_session_data.subscriber_username.toLowerCase() == username.toLowerCase()) {
username_match = true;
return_val = search_dir.replace(this.minisrv_config.config.SessionStore + self.path.sep, '').replace("user",'').split(self.path.sep);
}
} catch (e) { } catch (e) {
console.error(" # Error parsing Session Data JSON", file, e); console.error(" # Error parsing Session Data JSON", file, e);
username_match = true; username_match = true;
@@ -316,9 +320,10 @@ class WTVMail {
} }
getUserMailstore(username) { getUserMailstore(username) {
var ssid = this.checkUserExists(username); var user_data = this.checkUserExists(username);
if (ssid) { if (user_data) {
var user_wtvsession = new this.WTVClientSessionData(this.minisrv_config, ssid); var user_wtvsession = new this.WTVClientSessionData(this.minisrv_config, user_data[0]);
user_wtvsession.user_id = user_data[1];
var user_mailstore = new WTVMail(this.minisrv_config, ssid, user_wtvsession) var user_mailstore = new WTVMail(this.minisrv_config, ssid, user_wtvsession)
return user_mailstore; return user_mailstore;
} }

View File

@@ -28,26 +28,22 @@ class WTVRegister {
return (check1 && check2); return (check1 && check2);
} }
checkUsernameAvailable(username, directory = null) { checkUsernameAvailable(username, directory = null) {
// returns the user's ssid, and user_id and userid in an array if true, false if not
var username_match = false; var username_match = false;
var search_dir = this.session_store_dir; var search_dir = this.minisrv_config.config.SessionStore;
var return_val = false;
var self = this; var self = this;
if (directory) search_dir = directory; if (directory) search_dir = directory;
this.fs.readdirSync(search_dir).forEach(file => { this.fs.readdirSync(search_dir).forEach(file => {
if (self.fs.lstatSync(search_dir + self.path.sep + file).isDirectory()) { if (self.fs.lstatSync(search_dir + self.path.sep + file).isDirectory() && !return_val) {
return self. return_val = self.checkUsernameAvailable(username, search_dir + self.path.sep + file);
(username, search_dir + self.path.sep + file);
} }
if (!file.match(/.*\.json/ig)) return; if (!file.match(/.*\.json/ig)) return;
if (username_match) return; if (username_match) return;
try { try {
var temp_session_data_file = this.fs.readFileSync(search_dir + this.path.sep + file, 'Utf8'); var temp_session_data_file = self.fs.readFileSync(search_dir + self.path.sep + file, 'Utf8');
var temp_session_data = JSON.parse(temp_session_data_file); var temp_session_data = JSON.parse(temp_session_data_file);
if (temp_session_data.subscriber_username.toLowerCase() == username.toLowerCase()) username_match = true; if (temp_session_data.subscriber_username.toLowerCase() == username.toLowerCase()) username_match = true;
} catch (e) { } catch (e) {
@@ -58,6 +54,7 @@ class WTVRegister {
return !username_match; return !username_match;
} }
/** /**
* Generations regnstration template * Generations regnstration template
* @param {string} title HTML Page Title * @param {string} title HTML Page Title