mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-07 22:45:46 +01:00
resolved #1372 -- username clashes will now cause a random # to be appended to the username
This commit is contained in:
@@ -38,6 +38,7 @@
|
|||||||
"change_password_success": "Your password is updated!",
|
"change_password_success": "Your password is updated!",
|
||||||
"confirm_password": "Confirm Password",
|
"confirm_password": "Confirm Password",
|
||||||
"password": "Password",
|
"password": "Password",
|
||||||
|
"username_taken_workaround": "The username you requested was already taken, so we have altered it slightly. You are now known as <strong>%1</strong>",
|
||||||
|
|
||||||
"upload_picture": "Upload picture",
|
"upload_picture": "Upload picture",
|
||||||
"upload_a_picture": "Upload a picture",
|
"upload_a_picture": "Upload a picture",
|
||||||
|
|||||||
@@ -3,11 +3,13 @@
|
|||||||
var async = require('async'),
|
var async = require('async'),
|
||||||
winston = require('winston'),
|
winston = require('winston'),
|
||||||
cron = require('cron').CronJob,
|
cron = require('cron').CronJob,
|
||||||
|
nconf = require('nconf'),
|
||||||
|
|
||||||
db = require('./database'),
|
db = require('./database'),
|
||||||
utils = require('../public/src/utils'),
|
utils = require('../public/src/utils'),
|
||||||
events = require('./events'),
|
events = require('./events'),
|
||||||
User = require('./user');
|
User = require('./user'),
|
||||||
|
meta = require('./meta');
|
||||||
|
|
||||||
(function(Notifications) {
|
(function(Notifications) {
|
||||||
|
|
||||||
@@ -29,14 +31,22 @@ var async = require('async'),
|
|||||||
if (exists) {
|
if (exists) {
|
||||||
db.sortedSetRank('uid:' + uid + ':notifications:read', nid, function(err, rank) {
|
db.sortedSetRank('uid:' + uid + ':notifications:read', nid, function(err, rank) {
|
||||||
|
|
||||||
db.getObjectFields('notifications:' + nid, ['nid', 'from', 'text', 'importance', 'score', 'path', 'datetime', 'uniqueId'], function(err, notification) {
|
db.getObjectFields('notifications:' + nid, ['nid', 'from', 'text', 'image', 'importance', 'score', 'path', 'datetime', 'uniqueId'], function(err, notification) {
|
||||||
notification.read = rank !== null ? true:false;
|
notification.read = rank !== null ? true:false;
|
||||||
|
|
||||||
if (notification.from) {
|
if (notification.from && !notification.image) {
|
||||||
User.getUserField(notification.from, 'picture', function(err, picture) {
|
User.getUserField(notification.from, 'picture', function(err, picture) {
|
||||||
notification.image = picture;
|
notification.image = picture;
|
||||||
callback(notification);
|
callback(notification);
|
||||||
});
|
});
|
||||||
|
} else if (notification.image) {
|
||||||
|
switch(notification.image) {
|
||||||
|
case 'brand:logo':
|
||||||
|
notification.image = meta.config['brand:logo'] || nconf.get('relative_path') + '/logo.png';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
callback(notification);
|
||||||
} else {
|
} else {
|
||||||
callback(notification);
|
callback(notification);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var async = require('async'),
|
var async = require('async'),
|
||||||
db = require('./../database'),
|
db = require('../database'),
|
||||||
utils = require('./../../public/src/utils'),
|
utils = require('../../public/src/utils'),
|
||||||
validator = require('validator'),
|
validator = require('validator'),
|
||||||
plugins = require('./../plugins'),
|
plugins = require('../plugins'),
|
||||||
groups = require('./../groups');
|
groups = require('../groups'),
|
||||||
|
notifications = require('../notifications'),
|
||||||
|
translator = require('../../public/src/translator');
|
||||||
|
|
||||||
module.exports = function(User) {
|
module.exports = function(User) {
|
||||||
|
|
||||||
@@ -45,7 +47,23 @@ module.exports = function(User) {
|
|||||||
if (err) {
|
if (err) {
|
||||||
return next(err);
|
return next(err);
|
||||||
}
|
}
|
||||||
next(exists ? new Error('[[error:username-taken]]') : null);
|
if (exists) {
|
||||||
|
async.forever(function(next) {
|
||||||
|
// Append a random number to the username
|
||||||
|
var newUsername = userData.username + (Math.floor(Math.random() * 255) + 1);
|
||||||
|
User.exists(newUsername, function(err, exists) {
|
||||||
|
if (!exists) {
|
||||||
|
next(newUsername);
|
||||||
|
} else {
|
||||||
|
next();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}, function(username) {
|
||||||
|
next(null, username);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
next();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
function(next) {
|
function(next) {
|
||||||
@@ -71,6 +89,12 @@ module.exports = function(User) {
|
|||||||
}
|
}
|
||||||
userData = results[results.length - 1];
|
userData = results[results.length - 1];
|
||||||
|
|
||||||
|
// If a new username was picked...
|
||||||
|
if (results[3]) {
|
||||||
|
userData.username = results[3];
|
||||||
|
userData.userslug = utils.slugify(results[3]);
|
||||||
|
}
|
||||||
|
|
||||||
db.incrObjectField('global', 'nextUid', function(err, uid) {
|
db.incrObjectField('global', 'nextUid', function(err, uid) {
|
||||||
if(err) {
|
if(err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
@@ -125,6 +149,19 @@ module.exports = function(User) {
|
|||||||
|
|
||||||
groups.join('registered-users', uid);
|
groups.join('registered-users', uid);
|
||||||
|
|
||||||
|
// If their username was automatically changed...
|
||||||
|
if (results[3]) {
|
||||||
|
translator.translate('[[user:username_taken_workaround, ' + userData.username + ']]', function(notifText) {
|
||||||
|
notifications.create({
|
||||||
|
text: notifText,
|
||||||
|
picture: 'brand:logo',
|
||||||
|
datetime: Date.now()
|
||||||
|
}, function(nid) {
|
||||||
|
notifications.push(nid, uid);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (password) {
|
if (password) {
|
||||||
User.hashPassword(password, function(err, hash) {
|
User.hashPassword(password, function(err, hash) {
|
||||||
if(err) {
|
if(err) {
|
||||||
|
|||||||
Reference in New Issue
Block a user