mirror of
https://github.com/Foltik/Shimapan
synced 2024-12-02 18:48:32 -05:00
Fix username in use check and whitespace sanitization
This commit is contained in:
parent
150b736071
commit
c0f924bb59
@ -31,20 +31,33 @@ function checkInvite(code, cb) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Validates the username, then registers the user in the database using the given invite.
|
// Validates the username, then registers the user in the database using the given invite.
|
||||||
function registerUser(username, password, invite, sanitizeFn, cb) {
|
function registerUser(username, password, invite, sanitize, cb) {
|
||||||
async.series([
|
async.series([
|
||||||
function (cb) {
|
function (cb) {
|
||||||
// Canonicalize and sanitize the username, checking for HTML
|
// Canonicalize and sanitize the username, checking for HTML
|
||||||
var canonicalName = canonicalize(username);
|
var canonicalName = canonicalize(username);
|
||||||
var sanitizedName = sanitizeFn(canonicalName);
|
var sanitizedName = sanitize(canonicalName).replace(/\s/g,'');
|
||||||
|
|
||||||
if (sanitizedName !== canonicalName)
|
if (sanitizedName !== canonicalName)
|
||||||
cb('Username failed sanitization check.');
|
cb('Username contains invalid characters.');
|
||||||
else if (canonicalName.length > 36)
|
else if (canonicalName.length > 36)
|
||||||
cb('Username too long.');
|
cb('Username too long.');
|
||||||
else
|
else
|
||||||
cb(null);
|
cb(null);
|
||||||
},
|
},
|
||||||
|
function(cb) {
|
||||||
|
async.waterfall([
|
||||||
|
function(cb) {
|
||||||
|
User.count({canonicalname: canonicalize(username)}, cb);
|
||||||
|
},
|
||||||
|
function(count, cb) {
|
||||||
|
if (count !== 0)
|
||||||
|
cb('Username in use.');
|
||||||
|
else
|
||||||
|
cb(null);
|
||||||
|
}
|
||||||
|
], cb);
|
||||||
|
},
|
||||||
function (cb) {
|
function (cb) {
|
||||||
User.register(new User({
|
User.register(new User({
|
||||||
username: username,
|
username: username,
|
||||||
|
Loading…
Reference in New Issue
Block a user