Check if email is already taken when creating a new local account
This commit is contained in:
@ -96,18 +96,19 @@ exports.postSignup = function(req, res, next) {
|
|||||||
password: req.body.password
|
password: req.body.password
|
||||||
});
|
});
|
||||||
|
|
||||||
user.save(function(err) {
|
User.findOne({ email: req.body.email }, function(err, existingUser) {
|
||||||
if (err) {
|
if (existingUser) {
|
||||||
if (err.code === 11000) {
|
req.flash('errors', { msg: 'Account with that email address already exists.' });
|
||||||
req.flash('errors', { msg: 'User with that email already exists.' });
|
|
||||||
}
|
|
||||||
return res.redirect('/signup');
|
return res.redirect('/signup');
|
||||||
}
|
}
|
||||||
|
user.save(function(err) {
|
||||||
|
if (err) return next(err);
|
||||||
req.logIn(user, function(err) {
|
req.logIn(user, function(err) {
|
||||||
if (err) return next(err);
|
if (err) return next(err);
|
||||||
res.redirect('/');
|
res.redirect('/');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user