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

@ -15,7 +15,8 @@ var fs = require('fs'),
translator = require('./../public/src/translator'), translator = require('./../public/src/translator'),
db = require('./database'), db = require('./database'),
plugins = require('./plugins'), plugins = require('./plugins'),
user = require('./user'); user = require('./user'),
groups = require('./groups');
(function (Meta) { (function (Meta) {
Meta.restartRequired = false; Meta.restartRequired = false;
@ -521,6 +522,15 @@ var fs = require('fs'),
}; };
/* Assorted */ /* 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() { Meta.restart = function() {
if (process.send) { if (process.send) {
process.send({ process.send({

@ -2,6 +2,7 @@
var async = require('async'), var async = require('async'),
user = require('../user'), user = require('../user'),
groups = require('../groups'),
topics = require('../topics'), topics = require('../topics'),
utils = require('./../../public/src/utils'), utils = require('./../../public/src/utils'),
meta = require('../meta'), meta = require('../meta'),
@ -9,7 +10,7 @@ var async = require('async'),
SocketUser.exists = function(socket, data, callback) { SocketUser.exists = function(socket, data, callback) {
if (data && data.username) { 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'), validator = require('validator'),
plugins = require('../plugins'), plugins = require('../plugins'),
groups = require('../groups'), groups = require('../groups'),
meta = require('../meta'),
notifications = require('../notifications'), notifications = require('../notifications'),
translator = require('../../public/src/translator'); translator = require('../../public/src/translator');
@ -43,10 +44,11 @@ module.exports = function(User) {
} }
}, },
function(next) { function(next) {
User.exists(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) {
async.forever(function(next) { async.forever(function(next) {
var newUsername = userData.username + (Math.floor(Math.random() * 255) + 1); var newUsername = userData.username + (Math.floor(Math.random() * 255) + 1);

Loading…
Cancel
Save