possible fix for #1741

v1.18.x
barisusakli 11 years ago
parent 7c20e38556
commit 7454fd53b9

@ -27,34 +27,38 @@ module.exports = function(User) {
var password = userData.password; var password = userData.password;
userData.password = null; userData.password = null;
async.parallel([ async.parallel({
function(next) { emailValid: function(next) {
if (userData.email) { if (userData.email) {
next(!utils.isEmailValid(userData.email) ? new Error('[[error:invalid-email]]') : null); next(!utils.isEmailValid(userData.email) ? new Error('[[error:invalid-email]]') : null);
} else { } else {
next(); next();
} }
}, },
function(next) { userNameValid: function(next) {
next((!utils.isUserNameValid(userData.username) || !userData.userslug) ? new Error('[[error:invalid-username]]') : null); next((!utils.isUserNameValid(userData.username) || !userData.userslug) ? new Error('[[error:invalid-username]]') : null);
}, },
function(next) { passwordValid: function(next) {
if (password) { if (password) {
next(!utils.isPasswordValid(password) ? new Error('[[error:invalid-password]]') : null); next(!utils.isPasswordValid(password) ? new Error('[[error:invalid-password]]') : null);
} else { } else {
next(); next();
} }
}, },
function(next) { renamedUsername: function(next) {
meta.userOrGroupExists(userData.userslug, function(err, exists) { meta.userOrGroupExists(userData.userslug, function(err, exists) {
if (err) { if (err) {
return next(err); return next(err);
} }
if (exists) { if (exists) {
var newUsername = '';
async.forever(function(next) { async.forever(function(next) {
var newUsername = userData.username + (Math.floor(Math.random() * 255) + 1); newUsername = userData.username + (Math.floor(Math.random() * 255) + 1);
User.exists(newUsername, function(err, exists) { User.exists(newUsername, function(err, exists) {
if (err) {
return callback(err);
}
if (!exists) { if (!exists) {
next(newUsername); next(newUsername);
} else { } else {
@ -69,7 +73,7 @@ module.exports = function(User) {
} }
}); });
}, },
function(next) { emailAvailable: function(next) {
if (userData.email) { if (userData.email) {
User.email.available(userData.email, function(err, available) { User.email.available(userData.email, function(err, available) {
if (err) { if (err) {
@ -81,28 +85,34 @@ module.exports = function(User) {
next(); next();
} }
}, },
function(next) { customFields: function(next) {
plugins.fireHook('filter:user.custom_fields', userData, function(err, fields) { plugins.fireHook('filter:user.custom_fields', userData, function(err, fields) {
if (err) {
return next(err);
}
delete fields.username;
delete fields.userslug;
customFields = fields; customFields = fields;
next(err); next(err);
}); });
}, },
function(next) { userData: function(next) {
plugins.fireHook('filter:user.create', userData, function(err, filteredUserData){ plugins.fireHook('filter:user.create', userData, function(err, filteredUserData){
next(err, utils.merge(userData, filteredUserData)); next(err, utils.merge(userData, filteredUserData));
}); });
} }
], function(err, results) { }, function(err, results) {
if (err) { if (err) {
return callback(err); return callback(err);
} }
userData = results[results.length - 1]; userData = results.userData;
var userNameChanged = !!results[3]; var userNameChanged = !!results.renamedUsername;
// If a new username was picked... // If a new username was picked...
if (userNameChanged) { if (userNameChanged) {
userData.username = results[3]; userData.username = results.renamedUsername;
userData.userslug = utils.slugify(results[3]); userData.userslug = utils.slugify(results.renamedUsername);
} }
db.incrObjectField('global', 'nextUid', function(err, uid) { db.incrObjectField('global', 'nextUid', function(err, uid) {

Loading…
Cancel
Save