allow creating users without an email address

This commit is contained in:
Andris Reinman 2017-09-06 14:53:09 +03:00
parent 9eed937c5a
commit eb3c5cca67
3 changed files with 41 additions and 24 deletions

View file

@ -248,6 +248,7 @@ Creates a new user, returns the ID upon success.
- **username** (required) is the username of the user. This is not an email address but authentication username, use only letters and numbers - **username** (required) is the username of the user. This is not an email address but authentication username, use only letters and numbers
- **password** (required) is the password for the user - **password** (required) is the password for the user
- **address** is the main email address for the user. If address is not set then a new one is generated based on the username and current domain name - **address** is the main email address for the user. If address is not set then a new one is generated based on the username and current domain name
- **emptyAddress** if true, then do not set up an address for the user
- **name** is the name for the user - **name** is the name for the user
- **forward** is an email address to where all messages are forwarded to - **forward** is an email address to where all messages are forwarded to
- **targetUrl** is an URL to where all messages are uploaded to - **targetUrl** is an URL to where all messages are uploaded to

View file

@ -144,6 +144,9 @@ module.exports = (db, server, userHandler) => {
.required(), .required(),
address: Joi.string().email(), address: Joi.string().email(),
emptyAddress: Joi.boolean()
.truthy(['Y', 'true', 'yes', 1])
.default(false),
language: Joi.string() language: Joi.string()
.min(2) .min(2)

View file

@ -537,6 +537,10 @@ class UserHandler {
return callback(new Error('Database Error, failed to create user')); return callback(new Error('Database Error, failed to create user'));
} }
let ensureAddress = done => {
if (data.emptyAddress) {
return done(null, '');
}
let address = data.address ? data.address : data.username + '@' + (config.emailDomain || os.hostname()).toLowerCase(); let address = data.address ? data.address : data.username + '@' + (config.emailDomain || os.hostname()).toLowerCase();
// insert alias address to email address registry // insert alias address to email address registry
@ -563,7 +567,16 @@ class UserHandler {
response = 'Database Error, failed to create user'; response = 'Database Error, failed to create user';
} }
return callback(new Error(response)); return done(new Error(response));
}
done(null, address);
});
};
ensureAddress((err, address) => {
if (err) {
return callback(err);
} }
// register this address as the default address for that user // register this address as the default address for that user
@ -605,7 +618,7 @@ class UserHandler {
() => callback(null, id) () => callback(null, id)
); );
if (!this.messageHandler) { if (!this.messageHandler || data.emptyAddress) {
return createSuccess(); return createSuccess();
} }
@ -613,7 +626,7 @@ class UserHandler {
this.pushDefaultMessages( this.pushDefaultMessages(
userData, userData,
{ {
NAME: userData.name || address, NAME: userData.name || userData.username || address,
FNAME: parsedName.firstName, FNAME: parsedName.firstName,
LNAME: parsedName.lastName, LNAME: parsedName.lastName,
DOMAIN: address.substr(address.indexOf('@') + 1), DOMAIN: address.substr(address.indexOf('@') + 1),