2015-12-11 04:43:36 +00:00
|
|
|
/* jslint node: true */
|
|
|
|
'use strict';
|
|
|
|
|
2016-07-25 20:35:58 +00:00
|
|
|
// ENiGMA½
|
2017-11-24 23:23:15 +00:00
|
|
|
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').config;
|
|
|
|
const messageArea = require('./message_area.js');
|
2015-12-11 04:43:36 +00:00
|
|
|
|
|
|
|
exports.moduleInfo = {
|
|
|
|
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 = {
|
2015-12-11 04:43:36 +00:00
|
|
|
userName : 1,
|
|
|
|
password : 9,
|
|
|
|
confirm : 10,
|
|
|
|
errMsg : 11,
|
|
|
|
};
|
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
exports.getModule = class NewUserAppModule extends MenuModule {
|
2018-01-15 19:22:11 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
constructor(options) {
|
|
|
|
super(options);
|
2018-01-15 19:22:11 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
const self = this;
|
2015-12-11 04:43:36 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
this.menuMethods = {
|
|
|
|
//
|
|
|
|
// Validation stuff
|
|
|
|
//
|
|
|
|
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;
|
2018-01-15 19:22:11 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
if(err) {
|
|
|
|
errMsgView.setText(err.message);
|
|
|
|
err.view.clearText();
|
2015-12-11 04:43:36 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
if(err.view.getId() === MciViewIds.confirm) {
|
|
|
|
newFocusId = MciViewIds.password;
|
|
|
|
self.viewControllers.menu.getView(MciViewIds.password).clearText();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
errMsgView.clearText();
|
|
|
|
}
|
2015-12-11 04:43:36 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
return cb(newFocusId);
|
|
|
|
},
|
2015-12-11 04:43:36 +00:00
|
|
|
|
|
|
|
|
2016-02-03 04:35:59 +00:00
|
|
|
//
|
2017-01-26 05:18:05 +00:00
|
|
|
// Submit handlers
|
|
|
|
//
|
|
|
|
submitApplication : function(formData, extraArgs, cb) {
|
2017-02-18 20:21:18 +00:00
|
|
|
const newUser = new User();
|
2017-01-26 05:18:05 +00:00
|
|
|
|
|
|
|
newUser.username = formData.value.username;
|
|
|
|
|
|
|
|
//
|
|
|
|
// We have to disable ACS checks for initial default areas as the user is not yet ready
|
2018-01-15 19:22:11 +00:00
|
|
|
//
|
2017-01-26 05:18:05 +00:00
|
|
|
let confTag = messageArea.getDefaultMessageConferenceTag(self.client, true); // true=disableAcsCheck
|
|
|
|
let areaTag = messageArea.getDefaultMessageAreaTagByConfTag(self.client, confTag, true); // true=disableAcsCheck
|
|
|
|
|
|
|
|
// can't store undefined!
|
|
|
|
confTag = confTag || '';
|
|
|
|
areaTag = areaTag || '';
|
2018-01-15 19:22:11 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
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
|
2018-01-15 19:22:11 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
message_conf_tag : confTag,
|
|
|
|
message_area_tag : areaTag,
|
|
|
|
|
|
|
|
term_height : self.client.term.termHeight,
|
2018-01-15 19:22:11 +00:00
|
|
|
term_width : self.client.term.termWidth,
|
2017-01-26 05:18:05 +00:00
|
|
|
|
|
|
|
// :TODO: Other defaults
|
|
|
|
// :TODO: should probably have a place to create defaults/etc.
|
|
|
|
};
|
|
|
|
|
|
|
|
if('*' === Config.defaults.theme) {
|
|
|
|
newUser.properties.theme_id = theme.getRandomTheme();
|
2015-12-11 04:43:36 +00:00
|
|
|
} else {
|
2017-01-26 05:18:05 +00:00
|
|
|
newUser.properties.theme_id = Config.defaults.theme;
|
2015-12-11 04:43:36 +00:00
|
|
|
}
|
2018-01-15 19:22:11 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
// :TODO: User.create() should validate email uniqueness!
|
2017-02-18 20:21:18 +00:00
|
|
|
newUser.create(formData.value.password, err => {
|
2017-01-26 05:18:05 +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');
|
|
|
|
|
|
|
|
// Cache SysOp information now
|
|
|
|
// :TODO: Similar to bbs.js. DRY
|
|
|
|
if(newUser.isSysOp()) {
|
|
|
|
Config.general.sysOp = {
|
|
|
|
username : formData.value.username,
|
|
|
|
properties : newUser.properties,
|
|
|
|
};
|
|
|
|
}
|
2015-12-11 04:43:36 +00:00
|
|
|
|
2017-02-18 20:21:18 +00:00
|
|
|
if(User.AccountStatus.inactive === self.client.user.properties.account_status) {
|
2017-01-26 05:18:05 +00:00
|
|
|
return self.gotoMenu(extraArgs.inactive, cb);
|
|
|
|
} else {
|
|
|
|
//
|
|
|
|
// If active now, we need to call login() to authenticate
|
|
|
|
//
|
|
|
|
return login(self, formData, extraArgs, cb);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
mciReady(mciData, cb) {
|
|
|
|
return this.standardMCIReadyHandler(mciData, cb);
|
|
|
|
}
|
|
|
|
};
|