limiting user and group creation so that their slugs can't intersect.

v1.18.x
Julian Lam 11 years ago
parent 51e07e197b
commit 8a510c340b

@ -4,6 +4,7 @@
var async = require('async'),
winston = require('winston'),
user = require('./user'),
meta = require('./meta'),
db = require('./database'),
utils = require('../public/src/utils'),
@ -182,7 +183,7 @@
var system = true;
}
Groups.exists(name, function (err, exists) {
meta.userOrGroupExists(name, function (err, exists) {
if (err) {
return callback(err);
}

@ -15,7 +15,8 @@ var fs = require('fs'),
translator = require('./../public/src/translator'),
db = require('./database'),
plugins = require('./plugins'),
user = require('./user');
user = require('./user'),
groups = require('./groups');
(function (Meta) {
Meta.restartRequired = false;
@ -521,6 +522,15 @@ var fs = require('fs'),
};
/* Assorted */
Meta.userOrGroupExists = function(slug, callback) {
async.parallel([
async.apply(user.exists, slug),
async.apply(groups.exists, slug)
], function(err, results) {
callback(err, results.some(function(result) { return result }));
});
};
Meta.restart = function() {
if (process.send) {
process.send({

@ -2,6 +2,7 @@
var async = require('async'),
user = require('../user'),
groups = require('../groups'),
topics = require('../topics'),
utils = require('./../../public/src/utils'),
meta = require('../meta'),
@ -9,7 +10,7 @@ var async = require('async'),
SocketUser.exists = function(socket, data, callback) {
if (data && data.username) {
user.exists(utils.slugify(data.username), callback);
meta.userOrGroupExists(utils.slugify(data.username), callback);
}
};

@ -6,6 +6,7 @@ var async = require('async'),
validator = require('validator'),
plugins = require('../plugins'),
groups = require('../groups'),
meta = require('../meta'),
notifications = require('../notifications'),
translator = require('../../public/src/translator');
@ -43,10 +44,11 @@ module.exports = function(User) {
}
},
function(next) {
User.exists(userData.userslug, function(err, exists) {
meta.userOrGroupExists(userData.userslug, function(err, exists) {
if (err) {
return next(err);
}
if (exists) {
async.forever(function(next) {
var newUsername = userData.username + (Math.floor(Math.random() * 255) + 1);

Loading…
Cancel
Save