2015-12-11 04:43:36 +00:00
|
|
|
/* jslint node: true */
|
|
|
|
'use strict';
|
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
// ENiGMA½
|
2022-06-05 20:04:25 +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').get;
|
|
|
|
const messageArea = require('./message_area.js');
|
|
|
|
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
|
2022-06-05 20:04:25 +00:00
|
|
|
const _ = require('lodash');
|
2018-11-08 01:33:07 +00:00
|
|
|
|
2015-12-11 04:43:36 +00:00
|
|
|
exports.moduleInfo = {
|
2022-06-05 20:04:25 +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 = {
|
2022-06-05 20:04:25 +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-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
|
|
|
//
|
2022-06-05 20:04:25 +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')
|
|
|
|
);
|
2018-06-22 05:15:04 +00:00
|
|
|
},
|
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
viewValidationListener: function (err, cb) {
|
2018-06-22 05:15:04 +00:00
|
|
|
const errMsgView = self.viewControllers.menu.getView(MciViewIds.errMsg);
|
|
|
|
|
2023-02-04 20:44:55 +00:00
|
|
|
let newFocusId;
|
2022-06-05 20:04:25 +00:00
|
|
|
if (err) {
|
2023-02-04 20:44:55 +00:00
|
|
|
errMsgView.setText(err.friendlyText);
|
2018-06-22 05:15:04 +00:00
|
|
|
err.view.clearText();
|
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
if (err.view.getId() === MciViewIds.confirm) {
|
2018-06-22 05:15:04 +00:00
|
|
|
newFocusId = MciViewIds.password;
|
2022-06-05 20:04:25 +00:00
|
|
|
self.viewControllers.menu
|
|
|
|
.getView(MciViewIds.password)
|
|
|
|
.clearText();
|
2018-06-22 05:15:04 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
errMsgView.clearText();
|
|
|
|
}
|
|
|
|
|
2023-02-04 20:44:55 +00:00
|
|
|
return cb(err, newFocusId);
|
2018-06-22 05:15:04 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
//
|
2018-06-23 03:26:46 +00:00
|
|
|
// Submit handlers
|
2018-06-22 05:15:04 +00:00
|
|
|
//
|
2022-06-05 20:04:25 +00:00
|
|
|
submitApplication: function (formData, extraArgs, cb) {
|
2018-06-22 05:15:04 +00:00
|
|
|
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
|
|
|
//
|
2022-06-05 20:04:25 +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 = {
|
2022-06-05 20:04:25 +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(),
|
|
|
|
|
|
|
|
[UserProps.MessageConfTag]: confTag,
|
|
|
|
[UserProps.MessageAreaTag]: areaTag,
|
|
|
|
|
|
|
|
[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');
|
2022-06-05 20:04:25 +00:00
|
|
|
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 = {
|
2022-06-05 20:04:25 +00:00
|
|
|
password: formData.value.password,
|
|
|
|
sessionId: self.client.session.uniqueId, // used for events/etc.
|
2018-07-21 20:32:06 +00:00
|
|
|
};
|
|
|
|
newUser.create(createUserInfo, err => {
|
2022-06-12 20:12:03 +00:00
|
|
|
if (err) {
|
|
|
|
self.client.log.warn(
|
|
|
|
{ error: err, username: formData.value.username },
|
|
|
|
'New user creation failed'
|
|
|
|
);
|
2018-06-22 05:15:04 +00:00
|
|
|
|
|
|
|
self.gotoMenu(extraArgs.error, err => {
|
2022-06-05 20:04:25 +00:00
|
|
|
if (err) {
|
2018-06-22 05:15:04 +00:00
|
|
|
return self.prevMenu(cb);
|
|
|
|
}
|
|
|
|
return cb(null);
|
|
|
|
});
|
|
|
|
} else {
|
2022-06-12 20:12:03 +00:00
|
|
|
self.client.log.info(
|
|
|
|
{ username: formData.value.username, userId: newUser.userId },
|
|
|
|
`New user "${formData.value.username}" created`
|
|
|
|
);
|
2018-06-22 05:15:04 +00:00
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
// Cache SysOp information now
|
|
|
|
// :TODO: Similar to bbs.js. DRY
|
2022-06-05 20:04:25 +00:00
|
|
|
if (newUser.isSysOp()) {
|
2018-06-22 05:15:04 +00:00
|
|
|
config.general.sysOp = {
|
2022-06-05 20:04:25 +00:00
|
|
|
username: formData.value.username,
|
|
|
|
properties: newUser.properties,
|
2018-06-22 05:15:04 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-06-05 20:04:25 +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
|
|
|
};
|