More conversion to UserProps

This commit is contained in:
Bryan Ashby 2018-11-23 17:41:16 -07:00
parent b82c640014
commit 4050affedf
20 changed files with 123 additions and 95 deletions

View File

@ -2,13 +2,14 @@
'use strict'; 'use strict';
// ENiGMA½ // ENiGMA½
const logger = require('./logger.js'); const logger = require('./logger.js');
const Events = require('./events.js'); const Events = require('./events.js');
const UserProps = require('./user_property.js');
// deps // deps
const _ = require('lodash'); const _ = require('lodash');
const moment = require('moment'); const moment = require('moment');
const hashids = require('hashids'); const hashids = require('hashids');
exports.getActiveConnections = getActiveConnections; exports.getActiveConnections = getActiveConnections;
exports.getActiveNodeList = getActiveNodeList; exports.getActiveNodeList = getActiveNodeList;
@ -17,7 +18,7 @@ exports.removeClient = removeClient;
exports.getConnectionByUserId = getConnectionByUserId; exports.getConnectionByUserId = getConnectionByUserId;
const clientConnections = []; const clientConnections = [];
exports.clientConnections = clientConnections; exports.clientConnections = clientConnections;
function getActiveConnections() { return clientConnections; } function getActiveConnections() { return clientConnections; }
@ -46,11 +47,11 @@ function getActiveNodeList(authUsersOnly) {
// //
if(ac.user.isAuthenticated()) { if(ac.user.isAuthenticated()) {
entry.userName = ac.user.username; entry.userName = ac.user.username;
entry.realName = ac.user.properties.real_name; entry.realName = ac.user.properties[UserProps.RealName];
entry.location = ac.user.properties.location; entry.location = ac.user.properties[UserProps.Location];
entry.affils = entry.affiliation = ac.user.properties.affiliation; entry.affils = entry.affiliation = ac.user.properties[UserProps.Affiliations];
const diff = now.diff(moment(ac.user.properties.last_login_timestamp), 'minutes'); const diff = now.diff(moment(ac.user.properties[UserProps.LastLoginTs]), 'minutes');
entry.timeOn = moment.duration(diff, 'minutes'); entry.timeOn = moment.duration(diff, 'minutes');
} }
return entry; return entry;
@ -61,7 +62,7 @@ function addNewClient(client, clientSock) {
const id = client.session.id = clientConnections.push(client) - 1; const id = client.session.id = clientConnections.push(client) - 1;
const remoteAddress = client.remoteAddress = clientSock.remoteAddress; const remoteAddress = client.remoteAddress = clientSock.remoteAddress;
// create a uniqe identifier one-time ID for this session // create a unique identifier one-time ID for this session
client.session.uniqueId = new hashids('ENiGMA½ClientSession').encode([ id, moment().valueOf() ]); client.session.uniqueId = new hashids('ENiGMA½ClientSession').encode([ id, moment().valueOf() ]);
// Create a client specific logger // Create a client specific logger

View File

@ -2,6 +2,7 @@
'use strict'; 'use strict';
const FileEntry = require('./file_entry.js'); const FileEntry = require('./file_entry.js');
const UserProps = require('./user_property.js');
// deps // deps
const { partition } = require('lodash'); const { partition } = require('lodash');
@ -11,8 +12,8 @@ module.exports = class DownloadQueue {
this.client = client; this.client = client;
if(!Array.isArray(this.client.user.downloadQueue)) { if(!Array.isArray(this.client.user.downloadQueue)) {
if(this.client.user.properties.dl_queue) { if(this.client.user.properties[UserProps.DownloadQueue]) {
this.loadFromProperty(this.client.user.properties.dl_queue); this.loadFromProperty(this.client.user.properties[UserProps.DownloadQueue]);
} else { } else {
this.client.user.downloadQueue = []; this.client.user.downloadQueue = [];
} }

View File

@ -4,6 +4,7 @@
// ENiGMA½ // ENiGMA½
const Config = require('./config.js').get; const Config = require('./config.js').get;
const StatLog = require('./stat_log.js'); const StatLog = require('./stat_log.js');
const UserProps = require('./user_property.js');
// deps // deps
const fs = require('graceful-fs'); const fs = require('graceful-fs');
@ -168,7 +169,7 @@ module.exports = class DropFile {
'115200', '115200',
Config().general.boardName, Config().general.boardName,
this.client.user.userId.toString(), this.client.user.userId.toString(),
this.client.user.properties.real_name || this.client.user.username, this.client.user.properties[UserProps.RealName] || this.client.user.username,
this.client.user.username, this.client.user.username,
this.client.user.getLegacySecurityLevel().toString(), this.client.user.getLegacySecurityLevel().toString(),
'546', // :TODO: Minutes left! '546', // :TODO: Minutes left!
@ -189,21 +190,22 @@ module.exports = class DropFile {
const opUserName = /[^\s]*/.exec(StatLog.getSystemStat('sysop_username'))[0]; const opUserName = /[^\s]*/.exec(StatLog.getSystemStat('sysop_username'))[0];
const userName = /[^\s]*/.exec(this.client.user.username)[0]; const userName = /[^\s]*/.exec(this.client.user.username)[0];
const secLevel = this.client.user.getLegacySecurityLevel().toString(); const secLevel = this.client.user.getLegacySecurityLevel().toString();
const location = this.client.user.properties[UserProps.Location];
return iconv.encode( [ return iconv.encode( [
Config().general.boardName, // "The name of the system." Config().general.boardName, // "The name of the system."
opUserName, // "The sysop's name up to the first space." opUserName, // "The sysop's name up to the first space."
opUserName, // "The sysop's name following the first space." opUserName, // "The sysop's name following the first space."
'COM1', // "The serial port the modem is connected to, or 0 if logged in on console." 'COM1', // "The serial port the modem is connected to, or 0 if logged in on console."
'57600', // "The current port (DTE) rate." '57600', // "The current port (DTE) rate."
'0', // "The number "0"" '0', // "The number "0""
userName, // "The current user's name, up to the first space." userName, // "The current user's name, up to the first space."
userName, // "The current user's name, following the first space." userName, // "The current user's name, following the first space."
this.client.user.properties.location || '', // "Where the user lives, or a blank line if unknown." location || '', // "Where the user lives, or a blank line if unknown."
'1', // "The number "0" if TTY, or "1" if ANSI." '1', // "The number "0" if TTY, or "1" if ANSI."
secLevel, // "The number 5 for problem users, 30 for regular users, 80 for Aides, and 100 for Sysops." secLevel, // "The number 5 for problem users, 30 for regular users, 80 for Aides, and 100 for Sysops."
'546', // "The number of minutes left in the current user's account, limited to 546 to keep from overflowing other software." '546', // "The number of minutes left in the current user's account, limited to 546 to keep from overflowing other software."
'-1' // "The number "-1" if using an external serial driver or "0" if using internal serial routines." '-1' // "The number "-1" if using an external serial driver or "0" if using internal serial routines."
].join('\r\n') + '\r\n', 'cp437'); ].join('\r\n') + '\r\n', 'cp437');
} }

View File

@ -7,6 +7,7 @@ const ViewController = require('./view_controller.js').ViewContro
const getSortedAvailableFileAreas = require('./file_base_area.js').getSortedAvailableFileAreas; const getSortedAvailableFileAreas = require('./file_base_area.js').getSortedAvailableFileAreas;
const FileBaseFilters = require('./file_base_filter.js'); const FileBaseFilters = require('./file_base_filter.js');
const stringFormat = require('./string_format.js'); const stringFormat = require('./string_format.js');
const UserProps = require('./user_property.js');
// deps // deps
const async = require('async'); const async = require('async');
@ -111,7 +112,7 @@ exports.getModule = class FileAreaFilterEdit extends MenuModule {
// //
// If the item was also the active filter, we need to make a new one active // If the item was also the active filter, we need to make a new one active
// //
if(filterUuid === this.client.user.properties.file_base_filter_active_uuid) { if(filterUuid === this.client.user.properties[UserProps.FileBaseFilterActiveUuid]) {
const newActive = this.filtersArray[this.currentFilterIndex]; const newActive = this.filtersArray[this.currentFilterIndex];
if(newActive) { if(newActive) {
filters.setActive(newActive.uuid); filters.setActive(newActive.uuid);

View File

@ -66,7 +66,7 @@ module.exports = class FileBaseFilters {
} }
load() { load() {
let filtersProperty = this.client.user.properties.file_base_filters; let filtersProperty = this.client.user.properties[UserProps.FileBaseFilters];
let defaulted; let defaulted;
if(!filtersProperty) { if(!filtersProperty) {
filtersProperty = JSON.stringify(FileBaseFilters.getBuiltInSystemFilters()); filtersProperty = JSON.stringify(FileBaseFilters.getBuiltInSystemFilters());
@ -131,11 +131,11 @@ module.exports = class FileBaseFilters {
} }
static getActiveFilter(client) { static getActiveFilter(client) {
return new FileBaseFilters(client).get(client.user.properties.file_base_filter_active_uuid); return new FileBaseFilters(client).get(client.user.properties[UserProps.FileBaseFilterActiveUuid]);
} }
static getFileBaseLastViewedFileIdByUser(user) { static getFileBaseLastViewedFileIdByUser(user) {
return parseInt((user.properties.user_file_base_last_viewed || 0)); return parseInt((user.properties[UserProps.FileBaseLastViewedId] || 0));
} }
static setFileBaseLastViewedFileIdForUser(user, fileId, allowOlder, cb) { static setFileBaseLastViewedFileIdForUser(user, fileId, allowOlder, cb) {

View File

@ -24,6 +24,7 @@ const {
const Config = require('./config.js').get; const Config = require('./config.js').get;
const { getAddressedToInfo } = require('./mail_util.js'); const { getAddressedToInfo } = require('./mail_util.js');
const Events = require('./events.js'); const Events = require('./events.js');
const UserProps = require('./user_property.js');
// deps // deps
const async = require('async'); const async = require('async');
@ -738,7 +739,7 @@ exports.FullScreenEditorModule = exports.getModule = class FullScreenEditorModul
const fromView = self.viewControllers.header.getView(MciViewIds.header.from); const fromView = self.viewControllers.header.getView(MciViewIds.header.from);
const area = getMessageAreaByTag(self.messageAreaTag); const area = getMessageAreaByTag(self.messageAreaTag);
if(area && area.realNames) { if(area && area.realNames) {
fromView.setText(self.client.user.properties.real_name || self.client.user.username); fromView.setText(self.client.user.properties[UserProps.RealName] || self.client.user.username);
} else { } else {
fromView.setText(self.client.user.username); fromView.setText(self.client.user.username);
} }

View File

@ -6,6 +6,7 @@ const conf = require('./config.js');
const logger = require('./logger.js'); const logger = require('./logger.js');
const ServerModule = require('./server_module.js').ServerModule; const ServerModule = require('./server_module.js').ServerModule;
const clientConns = require('./client_connections.js'); const clientConns = require('./client_connections.js');
const UserProps = require('./user_property.js');
// deps // deps
const _ = require('lodash'); const _ = require('lodash');
@ -25,12 +26,12 @@ module.exports = class LoginServerModule extends ServerModule {
// //
const preLoginTheme = _.get(conf.config, 'theme.preLogin'); const preLoginTheme = _.get(conf.config, 'theme.preLogin');
if('*' === preLoginTheme) { if('*' === preLoginTheme) {
client.user.properties.theme_id = theme.getRandomTheme() || ''; client.user.properties[UserProps.ThemeId] = theme.getRandomTheme() || '';
} else { } else {
client.user.properties.theme_id = preLoginTheme; client.user.properties[UserProps.ThemeId] = preLoginTheme;
} }
theme.setClientTheme(client, client.user.properties.theme_id); theme.setClientTheme(client, client.user.properties[UserProps.ThemeId]);
return cb(null); // note: currently useless to use cb here - but this may change...again... return cb(null); // note: currently useless to use cb here - but this may change...again...
} }

View File

@ -304,8 +304,8 @@ function tempChangeMessageConfAndArea(client, areaTag) {
return false; return false;
} }
client.user.properties.message_conf_tag = confTag; client.user.properties[UserProps.MessageConfTag] = confTag;
client.user.properties.message_area_tag = areaTag; client.user.properties[UserProps.MessageAreaTag] = areaTag;
return true; return true;
} }

View File

@ -2,8 +2,10 @@
'use strict'; 'use strict';
const messageArea = require('../core/message_area.js'); const messageArea = require('../core/message_area.js');
const { get } = require('lodash'); const UserProps = require('./user_property.js');
// deps
const { get } = require('lodash');
exports.MessageAreaConfTempSwitcher = Sup => class extends Sup { exports.MessageAreaConfTempSwitcher = Sup => class extends Sup {
@ -15,8 +17,8 @@ exports.MessageAreaConfTempSwitcher = Sup => class extends Sup {
if(recordPrevious) { if(recordPrevious) {
this.prevMessageConfAndArea = { this.prevMessageConfAndArea = {
confTag : this.client.user.properties.message_conf_tag, confTag : this.client.user.properties[UserProps.MessageConfTag],
areaTag : this.client.user.properties.message_area_tag, areaTag : this.client.user.properties[UserProps.MessageAreaTag],
}; };
} }
@ -27,8 +29,8 @@ exports.MessageAreaConfTempSwitcher = Sup => class extends Sup {
tempMessageConfAndAreaRestore() { tempMessageConfAndAreaRestore() {
if(this.prevMessageConfAndArea) { if(this.prevMessageConfAndArea) {
this.client.user.properties.message_conf_tag = this.prevMessageConfAndArea.confTag; this.client.user.properties[UserProps.MessageConfTag] = this.prevMessageConfAndArea.confTag;
this.client.user.properties.message_area_tag = this.prevMessageConfAndArea.areaTag; this.client.user.properties[UserProps.MessageAreaTag] = this.prevMessageConfAndArea.areaTag;
} }
} }
}; };

View File

@ -5,6 +5,7 @@
const { MenuModule } = require('./menu_module.js'); const { MenuModule } = require('./menu_module.js');
const messageArea = require('./message_area.js'); const messageArea = require('./message_area.js');
const { Errors } = require('./enig_error.js'); const { Errors } = require('./enig_error.js');
const UserProps = require('./user_property.js');
// deps // deps
const async = require('async'); const async = require('async');
@ -110,7 +111,7 @@ exports.getModule = class MessageAreaListModule extends MenuModule {
initList() { initList() {
let index = 1; let index = 1;
this.messageAreas = messageArea.getSortedAvailMessageAreasByConfTag( this.messageAreas = messageArea.getSortedAvailMessageAreasByConfTag(
this.client.user.properties.message_conf_tag, this.client.user.properties[UserProps.MessageConfTag],
{ client : this.client } { client : this.client }
).map(area => { ).map(area => {
return { return {

View File

@ -3,6 +3,7 @@
const FullScreenEditorModule = require('./fse.js').FullScreenEditorModule; const FullScreenEditorModule = require('./fse.js').FullScreenEditorModule;
const persistMessage = require('./message_area.js').persistMessage; const persistMessage = require('./message_area.js').persistMessage;
const UserProps = require('./user_property.js');
const _ = require('lodash'); const _ = require('lodash');
const async = require('async'); const async = require('async');
@ -58,8 +59,10 @@ exports.getModule = class AreaPostFSEModule extends FullScreenEditorModule {
} }
enter() { enter() {
if(_.isString(this.client.user.properties.message_area_tag) && !_.isString(this.messageAreaTag)) { if(_.isString(this.client.user.properties[UserProps.MessageAreaTag]) &&
this.messageAreaTag = this.client.user.properties.message_area_tag; !_.isString(this.messageAreaTag))
{
this.messageAreaTag = this.client.user.properties[UserProps.MessageAreaTag];
} }
super.enter(); super.enter();

View File

@ -8,6 +8,7 @@ const messageArea = require('./message_area.js');
const MessageAreaConfTempSwitcher = require('./mod_mixins.js').MessageAreaConfTempSwitcher; const MessageAreaConfTempSwitcher = require('./mod_mixins.js').MessageAreaConfTempSwitcher;
const Errors = require('./enig_error.js').Errors; const Errors = require('./enig_error.js').Errors;
const Message = require('./message.js'); const Message = require('./message.js');
const UserProps = require('./user_property.js');
// deps // deps
const async = require('async'); const async = require('async');
@ -167,7 +168,7 @@ exports.getModule = class MessageListModule extends MessageAreaConfTempSwitcher(
if(this.config.messageAreaTag) { if(this.config.messageAreaTag) {
this.tempMessageConfAndAreaSwitch(this.config.messageAreaTag); this.tempMessageConfAndAreaSwitch(this.config.messageAreaTag);
} else { } else {
this.config.messageAreaTag = this.client.user.properties.message_area_tag; this.config.messageAreaTag = this.client.user.properties[UserProps.MessageAreaTag];
} }
} }
} }

View File

@ -2,17 +2,18 @@
'use strict'; 'use strict';
// ENiGMA½ // ENiGMA½
const Config = require('./config.js').get; const Config = require('./config.js').get;
const Log = require('./logger.js').log; const Log = require('./logger.js').log;
const { const {
getMessageAreaByTag, getMessageAreaByTag,
getMessageConferenceByTag getMessageConferenceByTag
} = require('./message_area.js'); } = require('./message_area.js');
const clientConnections = require('./client_connections.js'); const clientConnections = require('./client_connections.js');
const StatLog = require('./stat_log.js'); const StatLog = require('./stat_log.js');
const FileBaseFilters = require('./file_base_filter.js'); const FileBaseFilters = require('./file_base_filter.js');
const { formatByteSize } = require('./string_util.js'); const { formatByteSize } = require('./string_util.js');
const ANSI = require('./ansi_term.js'); const ANSI = require('./ansi_term.js');
const UserProps = require('./user_property.js');
// deps // deps
const packageJson = require('../package.json'); const packageJson = require('../package.json');
@ -83,7 +84,9 @@ const PREDEFINED_MCI_GENERATORS = {
UR : function realName(client) { return userStatAsString(client, 'real_name', ''); }, UR : function realName(client) { return userStatAsString(client, 'real_name', ''); },
LO : function location(client) { return userStatAsString(client, 'location', ''); }, LO : function location(client) { return userStatAsString(client, 'location', ''); },
UA : function age(client) { return client.user.getAge().toString(); }, UA : function age(client) { return client.user.getAge().toString(); },
BD : function birthdate(client) { return moment(client.user.properties.birthdate).format(client.currentTheme.helpers.getDateFormat()); }, // iNiQUiTY BD : function birthdate(client) { // iNiQUiTY
return moment(client.user.properties[UserProps.Birthdate]).format(client.currentTheme.helpers.getDateFormat());
},
US : function sex(client) { return userStatAsString(client, 'sex', ''); }, US : function sex(client) { return userStatAsString(client, 'sex', ''); },
UE : function emailAddres(client) { return userStatAsString(client, 'email_address', ''); }, UE : function emailAddres(client) { return userStatAsString(client, 'email_address', ''); },
UW : function webAddress(client) { return userStatAsString(client, 'web_address', ''); }, UW : function webAddress(client) { return userStatAsString(client, 'web_address', ''); },
@ -114,7 +117,9 @@ const PREDEFINED_MCI_GENERATORS = {
return getUserRatio(client, 'ul_total_bytes', 'dl_total_bytes'); return getUserRatio(client, 'ul_total_bytes', 'dl_total_bytes');
}, },
MS : function accountCreatedclient(client) { return moment(client.user.properties.account_created).format(client.currentTheme.helpers.getDateFormat()); }, MS : function accountCreatedclient(client) {
return moment(client.user.properties[UserProps.AccountCreated]).format(client.currentTheme.helpers.getDateFormat());
},
PS : function userPostCount(client) { return userStatAsString(client, 'post_count', 0); }, PS : function userPostCount(client) { return userStatAsString(client, 'post_count', 0); },
PC : function userPostCallRatio(client) { return getUserRatio(client, 'post_count', 'login_count'); }, PC : function userPostCallRatio(client) { return getUserRatio(client, 'post_count', 'login_count'); },
@ -123,19 +128,19 @@ const PREDEFINED_MCI_GENERATORS = {
}, },
MA : function messageAreaName(client) { MA : function messageAreaName(client) {
const area = getMessageAreaByTag(client.user.properties.message_area_tag); const area = getMessageAreaByTag(client.user.properties[UserProps.MessageAreaTag]);
return area ? area.name : ''; return area ? area.name : '';
}, },
MC : function messageConfName(client) { MC : function messageConfName(client) {
const conf = getMessageConferenceByTag(client.user.properties.message_conf_tag); const conf = getMessageConferenceByTag(client.user.properties[UserProps.MessageConfTag]);
return conf ? conf.name : ''; return conf ? conf.name : '';
}, },
ML : function messageAreaDescription(client) { ML : function messageAreaDescription(client) {
const area = getMessageAreaByTag(client.user.properties.message_area_tag); const area = getMessageAreaByTag(client.user.properties[UserProps.MessageAreaTag]);
return area ? area.desc : ''; return area ? area.desc : '';
}, },
CM : function messageConfDescription(client) { CM : function messageConfDescription(client) {
const conf = getMessageConferenceByTag(client.user.properties.message_conf_tag); const conf = getMessageConferenceByTag(client.user.properties[UserProps.MessageConfTag]);
return conf ? conf.desc : ''; return conf ? conf.desc : '';
}, },
@ -169,8 +174,9 @@ const PREDEFINED_MCI_GENERATORS = {
// Clean up CPU strings a bit for better display // Clean up CPU strings a bit for better display
// //
return os.cpus()[0].model return os.cpus()[0].model
.replace(/\(R\)|\(TM\)|processor|CPU/g, '') .replace(/\(R\)|\(TM\)|processor|CPU/ig, '')
.replace(/\s+(?= )/g, ''); .replace(/\s+(?= )/g, '')
.trim();
}, },
// :TODO: MCI for core count, e.g. os.cpus().length // :TODO: MCI for core count, e.g. os.cpus().length

View File

@ -14,7 +14,7 @@ const {
updateMessageAreaLastReadId, updateMessageAreaLastReadId,
getMessageIdNewerThanTimestampByArea getMessageIdNewerThanTimestampByArea
} = require('./message_area.js'); } = require('./message_area.js');
const stringFormat = require('./string_format.js'); const UserProps = require('./user_property.js');
// deps // deps
const async = require('async'); const async = require('async');
@ -183,8 +183,8 @@ exports.getModule = class SetNewScanDate extends MenuModule {
}); });
// Find current conf/area & move it directly under "All" // Find current conf/area & move it directly under "All"
const currConfTag = this.client.user.properties.message_conf_tag; const currConfTag = this.client.user.properties[UserProps.MessageConfTag];
const currAreaTag = this.client.user.properties.message_area_tag; const currAreaTag = this.client.user.properties[UserProps.MessageAreaTag];
if(currConfTag && currAreaTag) { if(currConfTag && currAreaTag) {
const confAreaIndex = selections.findIndex( confArea => { const confAreaIndex = selections.findIndex( confArea => {
return confArea.conf.confTag === currConfTag && confArea.area.areaTag === currAreaTag; return confArea.conf.confTag === currConfTag && confArea.area.areaTag === currAreaTag;

View File

@ -7,6 +7,7 @@ const ansiNormal = require('./ansi_term.js').normal;
const { userLogin } = require('./user_login.js'); const { userLogin } = require('./user_login.js');
const messageArea = require('./message_area.js'); const messageArea = require('./message_area.js');
const { ErrorReasons } = require('./enig_error.js'); const { ErrorReasons } = require('./enig_error.js');
const UserProps = require('./user_property.js');
// deps // deps
const _ = require('lodash'); const _ = require('lodash');
@ -105,7 +106,7 @@ function reloadMenu(menu, cb) {
function prevConf(callingMenu, formData, extraArgs, cb) { function prevConf(callingMenu, formData, extraArgs, cb) {
const confs = messageArea.getSortedAvailMessageConferences(callingMenu.client); const confs = messageArea.getSortedAvailMessageConferences(callingMenu.client);
const currIndex = confs.findIndex( e => e.confTag === callingMenu.client.user.properties.message_conf_tag) || confs.length; const currIndex = confs.findIndex( e => e.confTag === callingMenu.client.user.properties[UserProps.MessageConfTag]) || confs.length;
messageArea.changeMessageConference(callingMenu.client, confs[currIndex - 1].confTag, err => { messageArea.changeMessageConference(callingMenu.client, confs[currIndex - 1].confTag, err => {
if(err) { if(err) {
@ -118,7 +119,7 @@ function prevConf(callingMenu, formData, extraArgs, cb) {
function nextConf(callingMenu, formData, extraArgs, cb) { function nextConf(callingMenu, formData, extraArgs, cb) {
const confs = messageArea.getSortedAvailMessageConferences(callingMenu.client); const confs = messageArea.getSortedAvailMessageConferences(callingMenu.client);
let currIndex = confs.findIndex( e => e.confTag === callingMenu.client.user.properties.message_conf_tag); let currIndex = confs.findIndex( e => e.confTag === callingMenu.client.user.properties[UserProps.MessageConfTag]);
if(currIndex === confs.length - 1) { if(currIndex === confs.length - 1) {
currIndex = -1; currIndex = -1;
@ -134,8 +135,8 @@ function nextConf(callingMenu, formData, extraArgs, cb) {
} }
function prevArea(callingMenu, formData, extraArgs, cb) { function prevArea(callingMenu, formData, extraArgs, cb) {
const areas = messageArea.getSortedAvailMessageAreasByConfTag(callingMenu.client.user.properties.message_conf_tag); const areas = messageArea.getSortedAvailMessageAreasByConfTag(callingMenu.client.user.properties[UserProps.MessageConfTag]);
const currIndex = areas.findIndex( e => e.areaTag === callingMenu.client.user.properties.message_area_tag) || areas.length; const currIndex = areas.findIndex( e => e.areaTag === callingMenu.client.user.properties[UserProps.MessageAreaTag]) || areas.length;
messageArea.changeMessageArea(callingMenu.client, areas[currIndex - 1].areaTag, err => { messageArea.changeMessageArea(callingMenu.client, areas[currIndex - 1].areaTag, err => {
if(err) { if(err) {
@ -147,8 +148,8 @@ function prevArea(callingMenu, formData, extraArgs, cb) {
} }
function nextArea(callingMenu, formData, extraArgs, cb) { function nextArea(callingMenu, formData, extraArgs, cb) {
const areas = messageArea.getSortedAvailMessageAreasByConfTag(callingMenu.client.user.properties.message_conf_tag); const areas = messageArea.getSortedAvailMessageAreasByConfTag(callingMenu.client.user.properties[UserProps.MessageConfTag]);
let currIndex = areas.findIndex( e => e.areaTag === callingMenu.client.user.properties.message_area_tag); let currIndex = areas.findIndex( e => e.areaTag === callingMenu.client.user.properties[UserProps.MessageAreaTag]);
if(currIndex === areas.length - 1) { if(currIndex === areas.length - 1) {
currIndex = -1; currIndex = -1;

View File

@ -13,7 +13,9 @@ const Errors = require('./enig_error.js').Errors;
const ErrorReasons = require('./enig_error.js').ErrorReasons; const ErrorReasons = require('./enig_error.js').ErrorReasons;
const Events = require('./events.js'); const Events = require('./events.js');
const AnsiPrep = require('./ansi_prep.js'); const AnsiPrep = require('./ansi_prep.js');
const UserProps = require('./user_property.js');
// deps
const fs = require('graceful-fs'); const fs = require('graceful-fs');
const paths = require('path'); const paths = require('path');
const async = require('async'); const async = require('async');
@ -427,8 +429,8 @@ function getThemeArt(options, cb) {
// random // random
// //
const config = Config(); const config = Config();
if(!options.themeId && _.has(options, 'client.user.properties.theme_id')) { if(!options.themeId && _.has(options, [ 'client', 'user', 'properties', UserProps.ThemeId ])) {
options.themeId = options.client.user.properties.theme_id; options.themeId = options.client.user.properties[UserProps.ThemeId];
} else { } else {
options.themeId = config.theme.default; options.themeId = config.theme.default;
} }

View File

@ -55,7 +55,7 @@ exports.getModule = class UserConfigModule extends MenuModule {
// //
// If nothing changed, we know it's OK // If nothing changed, we know it's OK
// //
if(self.client.user.properties.email_address.toLowerCase() === data.toLowerCase()) { if(self.client.user.properties[UserProps.EmailAddress].toLowerCase() === data.toLowerCase()) {
return cb(null); return cb(null);
} }
@ -182,22 +182,22 @@ exports.getModule = class UserConfigModule extends MenuModule {
}), 'name'); }), 'name');
currentThemeIdIndex = Math.max(0, _.findIndex(self.availThemeInfo, function cmp(ti) { currentThemeIdIndex = Math.max(0, _.findIndex(self.availThemeInfo, function cmp(ti) {
return ti.themeId === self.client.user.properties.theme_id; return ti.themeId === self.client.user.properties[UserProps.ThemeId];
})); }));
callback(null); callback(null);
}, },
function populateViews(callback) { function populateViews(callback) {
var user = self.client.user; const user = self.client.user;
self.setViewText('menu', MciCodeIds.RealName, user.properties.real_name); self.setViewText('menu', MciCodeIds.RealName, user.properties[UserProps.RealName]);
self.setViewText('menu', MciCodeIds.BirthDate, moment(user.properties.birthdate).format('YYYYMMDD')); self.setViewText('menu', MciCodeIds.BirthDate, moment(user.properties[UserProps.Birthdate]).format('YYYYMMDD'));
self.setViewText('menu', MciCodeIds.Sex, user.properties.sex); self.setViewText('menu', MciCodeIds.Sex, user.properties[UserProps.Sex]);
self.setViewText('menu', MciCodeIds.Loc, user.properties.location); self.setViewText('menu', MciCodeIds.Loc, user.properties[UserProps.Location]);
self.setViewText('menu', MciCodeIds.Affils, user.properties.affiliation); self.setViewText('menu', MciCodeIds.Affils, user.properties[UserProps.Affiliations]);
self.setViewText('menu', MciCodeIds.Email, user.properties.email_address); self.setViewText('menu', MciCodeIds.Email, user.properties[UserProps.EmailAddress]);
self.setViewText('menu', MciCodeIds.Web, user.properties.web_address); self.setViewText('menu', MciCodeIds.Web, user.properties[UserProps.WebAddress]);
self.setViewText('menu', MciCodeIds.TermHeight, user.properties.term_height.toString()); self.setViewText('menu', MciCodeIds.TermHeight, user.properties[UserProps.TermHeight].toString());
var themeView = self.getView(MciCodeIds.Theme); var themeView = self.getView(MciCodeIds.Theme);

View File

@ -12,6 +12,7 @@ const {
Errors, Errors,
ErrorReasons ErrorReasons
} = require('./enig_error.js'); } = require('./enig_error.js');
const UserProps = require('./user_property.js');
// deps // deps
const async = require('async'); const async = require('async');
@ -74,24 +75,24 @@ function userLogin(client, username, password, cb) {
client.log.info('Successful login'); client.log.info('Successful login');
// User's unique session identifier is the same as the connection itself // User's unique session identifier is the same as the connection itself
user.sessionId = client.session.uniqueId; // convienence user.sessionId = client.session.uniqueId; // convenience
Events.emit(Events.getSystemEvents().UserLogin, { user } ); Events.emit(Events.getSystemEvents().UserLogin, { user } );
async.parallel( async.parallel(
[ [
function setTheme(callback) { function setTheme(callback) {
setClientTheme(client, user.properties.theme_id); setClientTheme(client, user.properties[UserProps.ThemeId]);
return callback(null); return callback(null);
}, },
function updateSystemLoginCount(callback) { function updateSystemLoginCount(callback) {
return StatLog.incrementSystemStat('login_count', 1, callback); return StatLog.incrementSystemStat('login_count', 1, callback); // :TODO: create system_property.js
}, },
function recordLastLogin(callback) { function recordLastLogin(callback) {
return StatLog.setUserStat(user, 'last_login_timestamp', StatLog.now, callback); return StatLog.setUserStat(user, UserProps.LastLoginTs, StatLog.now, callback);
}, },
function updateUserLoginCount(callback) { function updateUserLoginCount(callback) {
return StatLog.incrementUserStat(user, 'login_count', 1, callback); return StatLog.incrementUserStat(user, UserProps.LoginCount, 1, callback);
}, },
function recordLoginHistory(callback) { function recordLoginHistory(callback) {
const loginHistoryMax = Config().statLog.systemEvents.loginHistoryMax; const loginHistoryMax = Config().statLog.systemEvents.loginHistoryMax;

View File

@ -11,7 +11,7 @@ module.exports = {
PassPbkdf2Salt : 'pw_pbkdf2_salt', PassPbkdf2Salt : 'pw_pbkdf2_salt',
PassPbkdf2Dk : 'pw_pbkdf2_dk', PassPbkdf2Dk : 'pw_pbkdf2_dk',
AccountStatus : 'account_status', AccountStatus : 'account_status', // See User.AccountStatus enum
RealName : 'real_name', RealName : 'real_name',
Sex : 'sex', Sex : 'sex',
@ -24,10 +24,14 @@ module.exports = {
TermWidth : 'term_width', TermWidth : 'term_width',
ThemeId : 'theme_id', ThemeId : 'theme_id',
AccountCreated : 'account_created', AccountCreated : 'account_created',
LastLoginTs : 'last_login_timestamp',
LoginCount : 'login_count',
DownloadQueue : 'dl_queue', // download_queue.js
FailedLoginAttempts : 'failed_login_attempts', FailedLoginAttempts : 'failed_login_attempts',
AccountLockedTs : 'account_locked_timestamp', AccountLockedTs : 'account_locked_timestamp',
AccountLockedPrevStatus : 'account_locked_prev_status', // previous account status AccountLockedPrevStatus : 'account_locked_prev_status', // previous account status before lock out
EmailPwResetToken : 'email_password_reset_token', EmailPwResetToken : 'email_password_reset_token',
EmailPwResetTokenTs : 'email_password_reset_token_ts', EmailPwResetTokenTs : 'email_password_reset_token_ts',

View File

@ -59,7 +59,7 @@ class WebPasswordReset {
} }
User.getUser(userId, (err, user) => { User.getUser(userId, (err, user) => {
if(err || !user.properties.email_address) { if(err || !user.properties[UserProps.EmailAddress]) {
return callback(Errors.DoesNotExist('No email address associated with this user')); return callback(Errors.DoesNotExist('No email address associated with this user'));
} }
@ -105,13 +105,13 @@ class WebPasswordReset {
function buildAndSendEmail(user, textTemplate, htmlTemplate, callback) { function buildAndSendEmail(user, textTemplate, htmlTemplate, callback) {
const sendMail = require('./email.js').sendMail; const sendMail = require('./email.js').sendMail;
const resetUrl = webServer.instance.buildUrl(`/reset_password?token=${user.properties.email_password_reset_token}`); const resetUrl = webServer.instance.buildUrl(`/reset_password?token=${user.properties[UserProps.EmailPwResetToken]}`);
function replaceTokens(s) { function replaceTokens(s) {
return s return s
.replace(/%BOARDNAME%/g, Config().general.boardName) .replace(/%BOARDNAME%/g, Config().general.boardName)
.replace(/%USERNAME%/g, user.username) .replace(/%USERNAME%/g, user.username)
.replace(/%TOKEN%/g, user.properties.email_password_reset_token) .replace(/%TOKEN%/g, user.properties[UserProps.EmailPwResetToken])
.replace(/%RESET_URL%/g, resetUrl) .replace(/%RESET_URL%/g, resetUrl)
; ;
} }
@ -122,7 +122,7 @@ class WebPasswordReset {
} }
const message = { const message = {
to : `${user.properties.display_name||user.username} <${user.properties.email_address}>`, to : `${user.properties[UserProps.RealName]||user.username} <${user.properties[UserProps.EmailAddress]}>`,
// from will be filled in // from will be filled in
subject : 'Forgot Password', subject : 'Forgot Password',
text : textTemplate, text : textTemplate,