user fixes

This commit is contained in:
Baris Soner Usakli
2014-01-16 16:50:41 -05:00
parent 08f97efcd4
commit 0b132cadcf
3 changed files with 17 additions and 22 deletions

View File

@@ -139,8 +139,8 @@ Sockets.init = function() {
}
});
}
console.log('derp');
console.log(payload, callback);
var parts = payload.name.split('.'),
namespace = parts.slice(0, 1),
methodToCall = parts.reduce(function(prev, cur) {

View File

@@ -5,11 +5,7 @@ var user = require('../user'),
SocketUser.exists = function(socket, data, callback) {
if (data && data.username) {
user.exists(utils.slugify(data.username), function(exists) {
socket.emit('user.exists', {
exists: exists
});
});
user.exists(utils.slugify(data.username), callback);
}
};

View File

@@ -46,7 +46,10 @@ var bcrypt = require('bcrypt'),
}
},
function(next) {
User.exists(userslug, function(exists) {
User.exists(userslug, function(err, exists) {
if (err) {
return next(err);
}
next(exists ? new Error('Username taken!') : null);
});
},
@@ -193,9 +196,7 @@ var bcrypt = require('bcrypt'),
function isSignatureValid(next) {
if (data.signature !== undefined && data.signature.length > meta.config.maximumSignatureLength) {
next({
error: 'Signature can\'t be longer than ' + meta.config.maximumSignatureLength + ' characters!'
}, false);
next(new Error('Signature can\'t be longer than ' + meta.config.maximumSignatureLength + ' characters!'), false);
} else {
next(null, true);
}
@@ -217,9 +218,7 @@ var bcrypt = require('bcrypt'),
}
if (!available) {
next({
error: 'Email not available!'
}, false);
next(new Error('Email not available!'), false);
} else {
next(null, true);
}
@@ -237,16 +236,16 @@ var bcrypt = require('bcrypt'),
}
if(!utils.isUserNameValid(data.username) || !userslug) {
return next({
error: 'Invalid Username!'
}, false);
return next(new Error('Invalid Username!'), false);
}
User.exists(userslug, function(err, exists) {
if(err) {
return next(err);
}
User.exists(userslug, function(exists) {
if(exists) {
next({
error: 'Username not available!'
}, false);
next(new Error('Username not available!'), false);
} else {
next(null, true);
}
@@ -667,7 +666,7 @@ var bcrypt = require('bcrypt'),
User.exists = function(userslug, callback) {
User.getUidByUserslug(userslug, function(err, exists) {
callback( !! exists);
callback(err, !! exists);
});
};