Added validation check for duplicate emails

This commit is contained in:
Sahat Yalkabov
2013-11-18 14:07:59 -05:00
parent 94b04f54e5
commit 11b0ed44d2

View File

@ -38,8 +38,13 @@ exports.postSignup = function(req, res) {
// TODO: add User.schema.path validation
// TODO: check if user already exists in user.save() by catching that error
user.save(function(err) {
if (err) throw err;
console.log('New user created');
if (err) {
if (err.code === 11000) {
return res.send('Duplicate user detected');
} else {
return res.send('Database validation error');
}
}
req.login(user, function(err) {
if (err) throw err;
res.redirect('/');