Work on using UserProps, fix up ISO timestamps, etc.

This commit is contained in:
Bryan Ashby 2018-11-23 14:47:18 -07:00
parent 4bd340a480
commit b82c640014
10 changed files with 95 additions and 50 deletions

View File

@ -67,7 +67,13 @@ function loadDatabaseForMod(modInfo, cb) {
function getISOTimestampString(ts) { function getISOTimestampString(ts) {
ts = ts || moment(); ts = ts || moment();
return ts.format('YYYY-MM-DDTHH:mm:ss.SSSZ'); if(!moment.isMoment(ts)) {
if(_.isString(ts)) {
ts = ts.replace(/\//g, '-');
}
ts = moment(ts);
}
return ts.utc().format('YYYY-MM-DDTHH:mm:ss.SSS[Z]');
} }
function sanatizeString(s) { function sanatizeString(s) {

View File

@ -14,6 +14,7 @@ const resolveMimeType = require('./mime_util.js').resolveMimeType;
const stringFormat = require('./string_format.js'); const stringFormat = require('./string_format.js');
const wordWrapText = require('./word_wrap.js').wordWrapText; const wordWrapText = require('./word_wrap.js').wordWrapText;
const StatLog = require('./stat_log.js'); const StatLog = require('./stat_log.js');
const UserProps = require('./user_property.js');
// deps // deps
const _ = require('lodash'); const _ = require('lodash');
@ -136,11 +137,11 @@ function changeFileAreaWithOptions(client, areaTag, options, cb) {
}, },
function changeArea(area, callback) { function changeArea(area, callback) {
if(true === options.persist) { if(true === options.persist) {
client.user.persistProperty('file_area_tag', areaTag, err => { client.user.persistProperty(UserProps.FileAreaTag, areaTag, err => {
return callback(err, area); return callback(err, area);
}); });
} else { } else {
client.user.properties['file_area_tag'] = areaTag; client.user.properties[UserProps.FileAreaTag] = areaTag;
return callback(null, area); return callback(null, area);
} }
} }

View File

@ -1,9 +1,11 @@
/* jslint node: true */ /* jslint node: true */
'use strict'; 'use strict';
const UserProps = require('./user_property.js');
// deps // deps
const _ = require('lodash'); const _ = require('lodash');
const uuidV4 = require('uuid/v4'); const uuidV4 = require('uuid/v4');
module.exports = class FileBaseFilters { module.exports = class FileBaseFilters {
constructor(client) { constructor(client) {
@ -90,7 +92,7 @@ module.exports = class FileBaseFilters {
} }
persist(cb) { persist(cb) {
return this.client.user.persistProperty('file_base_filters', JSON.stringify(this.filters), cb); return this.client.user.persistProperty(UserProps.FileBaseFilters, JSON.stringify(this.filters), cb);
} }
cleanTags(tags) { cleanTags(tags) {
@ -102,7 +104,7 @@ module.exports = class FileBaseFilters {
if(activeFilter) { if(activeFilter) {
this.activeFilter = activeFilter; this.activeFilter = activeFilter;
this.client.user.persistProperty('file_base_filter_active_uuid', filterUuid); this.client.user.persistProperty(UserProps.FileBaseFilterActiveUuid, filterUuid);
return true; return true;
} }
@ -150,6 +152,6 @@ module.exports = class FileBaseFilters {
return; return;
} }
return user.persistProperty('user_file_base_last_viewed', fileId, cb); return user.persistProperty(UserProps.FileBaseLastViewedId, fileId, cb);
} }
}; };

View File

@ -8,6 +8,7 @@ const Message = require('./message.js');
const Log = require('./logger.js').log; const Log = require('./logger.js').log;
const msgNetRecord = require('./msg_network.js').recordMessage; const msgNetRecord = require('./msg_network.js').recordMessage;
const sortAreasOrConfs = require('./conf_area_util.js').sortAreasOrConfs; const sortAreasOrConfs = require('./conf_area_util.js').sortAreasOrConfs;
const UserProps = require('./user_property.js');
// deps // deps
const async = require('async'); const async = require('async');
@ -222,8 +223,8 @@ function changeMessageConference(client, confTag, cb) {
}, },
function changeConferenceAndArea(conf, areaInfo, callback) { function changeConferenceAndArea(conf, areaInfo, callback) {
const newProps = { const newProps = {
message_conf_tag : confTag, [ UserProps.MessageConfTag ] : confTag,
message_area_tag : areaInfo.areaTag, [ UserProps.MessageAreaTag ] : areaInfo.areaTag,
}; };
client.user.persistProperties(newProps, err => { client.user.persistProperties(newProps, err => {
callback(err, conf, areaInfo); callback(err, conf, areaInfo);
@ -262,11 +263,11 @@ function changeMessageAreaWithOptions(client, areaTag, options, cb) {
}, },
function changeArea(area, callback) { function changeArea(area, callback) {
if(true === options.persist) { if(true === options.persist) {
client.user.persistProperty('message_area_tag', areaTag, function persisted(err) { client.user.persistProperty(UserProps.MessageAreaTag, areaTag, function persisted(err) {
return callback(err, area); return callback(err, area);
}); });
} else { } else {
client.user.properties['message_area_tag'] = areaTag; client.user.properties[UserProps.MessageAreaTag] = areaTag;
return callback(null, area); return callback(null, area);
} }
} }

View File

@ -4,6 +4,8 @@
const paths = require('path'); const paths = require('path');
const os = require('os'); const os = require('os');
const moment = require('moment');
const packageJson = require('../package.json'); const packageJson = require('../package.json');
exports.isProduction = isProduction; exports.isProduction = isProduction;

View File

@ -8,9 +8,14 @@ const theme = require('./theme.js');
const login = require('./system_menu_method.js').login; const login = require('./system_menu_method.js').login;
const Config = require('./config.js').get; const Config = require('./config.js').get;
const messageArea = require('./message_area.js'); const messageArea = require('./message_area.js');
const {
getISOTimestampString
} = require('./database.js');
const UserProps = require('./user_property.js');
// deps // deps
const _ = require('lodash'); const _ = require('lodash');
const moment = require('moment');
exports.moduleInfo = { exports.moduleInfo = {
name : 'NUA', name : 'NUA',
@ -80,20 +85,20 @@ exports.getModule = class NewUserAppModule extends MenuModule {
areaTag = areaTag || ''; areaTag = areaTag || '';
newUser.properties = { newUser.properties = {
real_name : formData.value.realName, [ UserProps.RealName ] : formData.value.realName,
birthdate : new Date(Date.parse(formData.value.birthdate)).toISOString(), // :TODO: Use moment & explicit ISO string format [ UserProps.Birthdate ] : getISOTimestampString(formData.value.birthdate),
sex : formData.value.sex, [ UserProps.Sex ] : formData.value.sex,
location : formData.value.location, [ UserProps.Location ] : formData.value.location,
affiliation : formData.value.affils, [ UserProps.Affiliations ] : formData.value.affils,
email_address : formData.value.email, [ UserProps.EmailAddress ] : formData.value.email,
web_address : formData.value.web, [ UserProps.WebAddress ] : formData.value.web,
account_created : new Date().toISOString(), // :TODO: Use moment & explicit ISO string format [ UserProps.AccountCreated ] : getISOTimestampString(),
message_conf_tag : confTag, [ UserProps.MessageConfTag ] : confTag,
message_area_tag : areaTag, [ UserProps.MessageAreaTag ] : areaTag,
term_height : self.client.term.termHeight, [ UserProps.TermHeight ] : self.client.term.termHeight,
term_width : self.client.term.termWidth, [ UserProps.TermWidth ] : self.client.term.termWidth,
// :TODO: Other defaults // :TODO: Other defaults
// :TODO: should probably have a place to create defaults/etc. // :TODO: should probably have a place to create defaults/etc.
@ -101,9 +106,9 @@ exports.getModule = class NewUserAppModule extends MenuModule {
const defaultTheme = _.get(config, 'theme.default'); const defaultTheme = _.get(config, 'theme.default');
if('*' === defaultTheme) { if('*' === defaultTheme) {
newUser.properties.theme_id = theme.getRandomTheme(); newUser.properties[UserProps.ThemeId] = theme.getRandomTheme();
} else { } else {
newUser.properties.theme_id = defaultTheme; newUser.properties[UserProps.ThemeId] = defaultTheme;
} }
// :TODO: User.create() should validate email uniqueness! // :TODO: User.create() should validate email uniqueness!
@ -133,7 +138,7 @@ exports.getModule = class NewUserAppModule extends MenuModule {
}; };
} }
if(User.AccountStatus.inactive === self.client.user.properties.account_status) { if(User.AccountStatus.inactive === self.client.user.properties[UserProps.AccountStatus]) {
return self.gotoMenu(extraArgs.inactive, cb); return self.gotoMenu(extraArgs.inactive, cb);
} else { } else {
// //

View File

@ -2,10 +2,12 @@
'use strict'; 'use strict';
const sysDb = require('./database.js').dbs.system; const sysDb = require('./database.js').dbs.system;
const {
getISOTimestampString
} = require('./database.js');
// deps // deps
const _ = require('lodash'); const _ = require('lodash');
const moment = require('moment');
/* /*
System Event Log & Stats System Event Log & Stats
@ -149,7 +151,9 @@ class StatLog {
} }
// the time "now" in the ISO format we use and love :) // the time "now" in the ISO format we use and love :)
get now() { return moment().format('YYYY-MM-DDTHH:mm:ss.SSSZ'); } get now() {
return getISOTimestampString();
}
appendSystemLogEntry(logName, logValue, keep, keepType, cb) { appendSystemLogEntry(logName, logValue, keep, keepType, cb) {
sysDb.run( sysDb.run(

View File

@ -1,11 +1,17 @@
/* jslint node: true */ /* jslint node: true */
'use strict'; 'use strict';
// ENiGMA½
const MenuModule = require('./menu_module.js').MenuModule; const MenuModule = require('./menu_module.js').MenuModule;
const ViewController = require('./view_controller.js').ViewController; const ViewController = require('./view_controller.js').ViewController;
const theme = require('./theme.js'); const theme = require('./theme.js');
const sysValidate = require('./system_view_validate.js'); const sysValidate = require('./system_view_validate.js');
const UserProps = require('./user_property.js');
const {
getISOTimestampString
} = require('./database.js');
// deps
const async = require('async'); const async = require('async');
const assert = require('assert'); const assert = require('assert');
const _ = require('lodash'); const _ = require('lodash');
@ -101,15 +107,15 @@ exports.getModule = class UserConfigModule extends MenuModule {
assert(formData.value.password === formData.value.passwordConfirm); assert(formData.value.password === formData.value.passwordConfirm);
const newProperties = { const newProperties = {
real_name : formData.value.realName, [ UserProps.RealName ] : formData.value.realName,
birthdate : new Date(Date.parse(formData.value.birthdate)).toISOString(), [ UserProps.Birthdate ] : getISOTimestampString(formData.value.birthdate),
sex : formData.value.sex, [ UserProps.Sex ] : formData.value.sex,
location : formData.value.location, [ UserProps.Location ] : formData.value.location,
affiliation : formData.value.affils, [ UserProps.Affiliations ] : formData.value.affils,
email_address : formData.value.email, [ UserProps.EmailAddress ] : formData.value.email,
web_address : formData.value.web, [ UserProps.WebAddress ] : formData.value.web,
term_height : formData.value.termHeight.toString(), [ UserProps.TermHeight ] : formData.value.termHeight.toString(),
theme_id : self.availThemeInfo[formData.value.theme].themeId, [ UserProps.ThemeId ] : self.availThemeInfo[formData.value.theme].themeId,
}; };
// runtime set theme // runtime set theme

View File

@ -8,18 +8,36 @@
// can utilize their own properties as well! // can utilize their own properties as well!
// //
module.exports = { module.exports = {
PassPbkdf2Salt : 'pw_pbkdf2_salt', PassPbkdf2Salt : 'pw_pbkdf2_salt',
PassPbkdf2Dk : 'pw_pbkdf2_dk', PassPbkdf2Dk : 'pw_pbkdf2_dk',
AccountStatus : 'account_status', AccountStatus : 'account_status',
Birthdate : 'birthdate', RealName : 'real_name',
Sex : 'sex',
Birthdate : 'birthdate',
Location : 'location',
Affiliations : 'affiliation',
EmailAddress : 'email_address',
WebAddress : 'web_address',
TermHeight : 'term_height',
TermWidth : 'term_width',
ThemeId : 'theme_id',
AccountCreated : 'account_created',
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
EmailPwResetToken : 'email_password_reset_token', EmailPwResetToken : 'email_password_reset_token',
EmailPwResetTokenTs : 'email_password_reset_token_ts', EmailPwResetTokenTs : 'email_password_reset_token_ts',
FileAreaTag : 'file_area_tag',
FileBaseFilters : 'file_base_filters',
FileBaseFilterActiveUuid : 'file_base_filter_active_uuid',
FileBaseLastViewedId : 'user_file_base_last_viewed',
MessageConfTag : 'message_conf_tag',
MessageAreaTag : 'message_area_tag',
}; };

View File

@ -79,8 +79,8 @@ class WebPasswordReset {
token = token.toString('hex'); token = token.toString('hex');
const newProperties = { const newProperties = {
email_password_reset_token : token, [ UserProps.EmailPwResetToken ] : token,
email_password_reset_token_ts : getISOTimestampString(), [ UserProps.EmailPwResetTokenTs ] : getISOTimestampString(),
}; };
// we simply place the reset token in the user's properties // we simply place the reset token in the user's properties