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