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) {
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) {

View File

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

View File

@ -1,9 +1,11 @@
/* jslint node: true */
'use strict';
const UserProps = require('./user_property.js');
// deps
const _ = require('lodash');
const uuidV4 = require('uuid/v4');
const _ = require('lodash');
const uuidV4 = require('uuid/v4');
module.exports = class FileBaseFilters {
constructor(client) {
@ -90,7 +92,7 @@ module.exports = class FileBaseFilters {
}
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) {
@ -102,7 +104,7 @@ module.exports = class FileBaseFilters {
if(activeFilter) {
this.activeFilter = activeFilter;
this.client.user.persistProperty('file_base_filter_active_uuid', filterUuid);
this.client.user.persistProperty(UserProps.FileBaseFilterActiveUuid, filterUuid);
return true;
}
@ -150,6 +152,6 @@ module.exports = class FileBaseFilters {
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 msgNetRecord = require('./msg_network.js').recordMessage;
const sortAreasOrConfs = require('./conf_area_util.js').sortAreasOrConfs;
const UserProps = require('./user_property.js');
// deps
const async = require('async');
@ -222,8 +223,8 @@ function changeMessageConference(client, confTag, cb) {
},
function changeConferenceAndArea(conf, areaInfo, callback) {
const newProps = {
message_conf_tag : confTag,
message_area_tag : areaInfo.areaTag,
[ UserProps.MessageConfTag ] : confTag,
[ UserProps.MessageAreaTag ] : areaInfo.areaTag,
};
client.user.persistProperties(newProps, err => {
callback(err, conf, areaInfo);
@ -262,11 +263,11 @@ function changeMessageAreaWithOptions(client, areaTag, options, cb) {
},
function changeArea(area, callback) {
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);
});
} else {
client.user.properties['message_area_tag'] = areaTag;
client.user.properties[UserProps.MessageAreaTag] = areaTag;
return callback(null, area);
}
}

View File

@ -4,6 +4,8 @@
const paths = require('path');
const os = require('os');
const moment = require('moment');
const packageJson = require('../package.json');
exports.isProduction = isProduction;
@ -57,4 +59,4 @@ function valueAsArray(value) {
return [];
}
return Array.isArray(value) ? value : [ value ];
}
}

View File

@ -8,9 +8,14 @@ const theme = require('./theme.js');
const login = require('./system_menu_method.js').login;
const Config = require('./config.js').get;
const messageArea = require('./message_area.js');
const {
getISOTimestampString
} = require('./database.js');
const UserProps = require('./user_property.js');
// deps
const _ = require('lodash');
const moment = require('moment');
exports.moduleInfo = {
name : 'NUA',
@ -80,20 +85,20 @@ exports.getModule = class NewUserAppModule extends MenuModule {
areaTag = areaTag || '';
newUser.properties = {
real_name : formData.value.realName,
birthdate : new Date(Date.parse(formData.value.birthdate)).toISOString(), // :TODO: Use moment & explicit ISO string format
sex : formData.value.sex,
location : formData.value.location,
affiliation : formData.value.affils,
email_address : formData.value.email,
web_address : formData.value.web,
account_created : new Date().toISOString(), // :TODO: Use moment & explicit ISO string format
[ UserProps.RealName ] : formData.value.realName,
[ UserProps.Birthdate ] : getISOTimestampString(formData.value.birthdate),
[ UserProps.Sex ] : formData.value.sex,
[ UserProps.Location ] : formData.value.location,
[ UserProps.Affiliations ] : formData.value.affils,
[ UserProps.EmailAddress ] : formData.value.email,
[ UserProps.WebAddress ] : formData.value.web,
[ UserProps.AccountCreated ] : getISOTimestampString(),
message_conf_tag : confTag,
message_area_tag : areaTag,
[ UserProps.MessageConfTag ] : confTag,
[ UserProps.MessageAreaTag ] : areaTag,
term_height : self.client.term.termHeight,
term_width : self.client.term.termWidth,
[ UserProps.TermHeight ] : self.client.term.termHeight,
[ UserProps.TermWidth ] : self.client.term.termWidth,
// :TODO: Other defaults
// :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');
if('*' === defaultTheme) {
newUser.properties.theme_id = theme.getRandomTheme();
newUser.properties[UserProps.ThemeId] = theme.getRandomTheme();
} else {
newUser.properties.theme_id = defaultTheme;
newUser.properties[UserProps.ThemeId] = defaultTheme;
}
// :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);
} else {
//

View File

@ -2,10 +2,12 @@
'use strict';
const sysDb = require('./database.js').dbs.system;
const {
getISOTimestampString
} = require('./database.js');
// deps
const _ = require('lodash');
const moment = require('moment');
/*
System Event Log & Stats
@ -149,7 +151,9 @@ class StatLog {
}
// 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) {
sysDb.run(

View File

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

View File

@ -8,18 +8,36 @@
// can utilize their own properties as well!
//
module.exports = {
PassPbkdf2Salt : 'pw_pbkdf2_salt',
PassPbkdf2Dk : 'pw_pbkdf2_dk',
PassPbkdf2Salt : 'pw_pbkdf2_salt',
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',
AccountLockedTs : 'account_locked_timestamp',
AccountLockedPrevStatus : 'account_locked_prev_status', // previous account status
FailedLoginAttempts : 'failed_login_attempts',
AccountLockedTs : 'account_locked_timestamp',
AccountLockedPrevStatus : 'account_locked_prev_status', // previous account status
EmailPwResetToken : 'email_password_reset_token',
EmailPwResetTokenTs : 'email_password_reset_token_ts',
EmailPwResetToken : 'email_password_reset_token',
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');
const newProperties = {
email_password_reset_token : token,
email_password_reset_token_ts : getISOTimestampString(),
[ UserProps.EmailPwResetToken ] : token,
[ UserProps.EmailPwResetTokenTs ] : getISOTimestampString(),
};
// we simply place the reset token in the user's properties