2015-12-11 04:43:36 +00:00
|
|
|
/* jslint node: true */
|
|
|
|
'use strict';
|
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
// ENiGMA½
|
|
|
|
const MenuModule = require('./menu_module.js').MenuModule;
|
|
|
|
const User = require('./user.js');
|
|
|
|
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');
|
2018-11-23 21:47:18 +00:00
|
|
|
const {
|
|
|
|
getISOTimestampString
|
|
|
|
} = require('./database.js');
|
|
|
|
const UserProps = require('./user_property.js');
|
2015-12-11 04:43:36 +00:00
|
|
|
|
2018-11-08 01:33:07 +00:00
|
|
|
// deps
|
|
|
|
const _ = require('lodash');
|
2018-11-23 21:47:18 +00:00
|
|
|
const moment = require('moment');
|
2018-11-08 01:33:07 +00:00
|
|
|
|
2015-12-11 04:43:36 +00:00
|
|
|
exports.moduleInfo = {
|
2018-06-23 03:26:46 +00:00
|
|
|
name : 'NUA',
|
|
|
|
desc : 'New User Application',
|
2015-12-24 18:55:17 +00:00
|
|
|
};
|
2015-12-11 04:43:36 +00:00
|
|
|
|
2016-07-25 20:35:58 +00:00
|
|
|
const MciViewIds = {
|
2018-06-23 03:26:46 +00:00
|
|
|
userName : 1,
|
|
|
|
password : 9,
|
|
|
|
confirm : 10,
|
|
|
|
errMsg : 11,
|
2015-12-11 04:43:36 +00:00
|
|
|
};
|
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
exports.getModule = class NewUserAppModule extends MenuModule {
|
2018-01-15 19:22:11 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
constructor(options) {
|
|
|
|
super(options);
|
|
|
|
|
|
|
|
const self = this;
|
|
|
|
|
|
|
|
this.menuMethods = {
|
|
|
|
//
|
2018-06-23 03:26:46 +00:00
|
|
|
// Validation stuff
|
2018-06-22 05:15:04 +00:00
|
|
|
//
|
|
|
|
validatePassConfirmMatch : function(data, cb) {
|
|
|
|
const passwordView = self.viewControllers.menu.getView(MciViewIds.password);
|
|
|
|
return cb(passwordView.getData() === data ? null : new Error('Passwords do not match'));
|
|
|
|
},
|
|
|
|
|
|
|
|
viewValidationListener : function(err, cb) {
|
|
|
|
const errMsgView = self.viewControllers.menu.getView(MciViewIds.errMsg);
|
|
|
|
let newFocusId;
|
|
|
|
|
|
|
|
if(err) {
|
|
|
|
errMsgView.setText(err.message);
|
|
|
|
err.view.clearText();
|
|
|
|
|
|
|
|
if(err.view.getId() === MciViewIds.confirm) {
|
|
|
|
newFocusId = MciViewIds.password;
|
|
|
|
self.viewControllers.menu.getView(MciViewIds.password).clearText();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
errMsgView.clearText();
|
|
|
|
}
|
|
|
|
|
|
|
|
return cb(newFocusId);
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
//
|
2018-06-23 03:26:46 +00:00
|
|
|
// Submit handlers
|
2018-06-22 05:15:04 +00:00
|
|
|
//
|
|
|
|
submitApplication : function(formData, extraArgs, cb) {
|
|
|
|
const newUser = new User();
|
|
|
|
const config = Config();
|
|
|
|
|
|
|
|
newUser.username = formData.value.username;
|
|
|
|
|
|
|
|
//
|
2018-06-23 03:26:46 +00:00
|
|
|
// We have to disable ACS checks for initial default areas as the user is not yet ready
|
2018-06-22 05:15:04 +00:00
|
|
|
//
|
2018-06-23 03:26:46 +00:00
|
|
|
let confTag = messageArea.getDefaultMessageConferenceTag(self.client, true); // true=disableAcsCheck
|
|
|
|
let areaTag = messageArea.getDefaultMessageAreaTagByConfTag(self.client, confTag, true); // true=disableAcsCheck
|
2018-06-22 05:15:04 +00:00
|
|
|
|
|
|
|
// can't store undefined!
|
|
|
|
confTag = confTag || '';
|
|
|
|
areaTag = areaTag || '';
|
|
|
|
|
|
|
|
newUser.properties = {
|
2018-11-23 21:47:18 +00:00
|
|
|
[ 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(),
|
2018-06-22 05:15:04 +00:00
|
|
|
|
2018-11-23 21:47:18 +00:00
|
|
|
[ UserProps.MessageConfTag ] : confTag,
|
|
|
|
[ UserProps.MessageAreaTag ] : areaTag,
|
2018-06-22 05:15:04 +00:00
|
|
|
|
2018-11-23 21:47:18 +00:00
|
|
|
[ UserProps.TermHeight ] : self.client.term.termHeight,
|
|
|
|
[ UserProps.TermWidth ] : self.client.term.termWidth,
|
2018-06-22 05:15:04 +00:00
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
// :TODO: Other defaults
|
|
|
|
// :TODO: should probably have a place to create defaults/etc.
|
2018-06-22 05:15:04 +00:00
|
|
|
};
|
|
|
|
|
2018-11-08 01:33:07 +00:00
|
|
|
const defaultTheme = _.get(config, 'theme.default');
|
|
|
|
if('*' === defaultTheme) {
|
2018-11-23 21:47:18 +00:00
|
|
|
newUser.properties[UserProps.ThemeId] = theme.getRandomTheme();
|
2018-06-22 05:15:04 +00:00
|
|
|
} else {
|
2018-11-23 21:47:18 +00:00
|
|
|
newUser.properties[UserProps.ThemeId] = defaultTheme;
|
2018-06-22 05:15:04 +00:00
|
|
|
}
|
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
// :TODO: User.create() should validate email uniqueness!
|
2018-07-21 20:32:06 +00:00
|
|
|
const createUserInfo = {
|
|
|
|
password : formData.value.password,
|
|
|
|
sessionId : self.client.session.uniqueId, // used for events/etc.
|
|
|
|
};
|
|
|
|
newUser.create(createUserInfo, err => {
|
2018-06-22 05:15:04 +00:00
|
|
|
if(err) {
|
|
|
|
self.client.log.info( { error : err, username : formData.value.username }, 'New user creation failed');
|
|
|
|
|
|
|
|
self.gotoMenu(extraArgs.error, err => {
|
|
|
|
if(err) {
|
|
|
|
return self.prevMenu(cb);
|
|
|
|
}
|
|
|
|
return cb(null);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
self.client.log.info( { username : formData.value.username, userId : newUser.userId }, 'New user created');
|
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
// Cache SysOp information now
|
|
|
|
// :TODO: Similar to bbs.js. DRY
|
2018-06-22 05:15:04 +00:00
|
|
|
if(newUser.isSysOp()) {
|
|
|
|
config.general.sysOp = {
|
2018-06-23 03:26:46 +00:00
|
|
|
username : formData.value.username,
|
|
|
|
properties : newUser.properties,
|
2018-06-22 05:15:04 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-11-23 21:47:18 +00:00
|
|
|
if(User.AccountStatus.inactive === self.client.user.properties[UserProps.AccountStatus]) {
|
2018-06-22 05:15:04 +00:00
|
|
|
return self.gotoMenu(extraArgs.inactive, cb);
|
|
|
|
} else {
|
|
|
|
//
|
2018-06-23 03:26:46 +00:00
|
|
|
// If active now, we need to call login() to authenticate
|
2018-06-22 05:15:04 +00:00
|
|
|
//
|
|
|
|
return login(self, formData, extraArgs, cb);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
mciReady(mciData, cb) {
|
|
|
|
return this.standardMCIReadyHandler(mciData, cb);
|
|
|
|
}
|
2017-01-26 05:18:05 +00:00
|
|
|
};
|