Changed updatePassword controller validation to use express-validator instead of custom if statements
parent
c0e1a1129a
commit
7396a6d7ab
|
@ -141,13 +141,14 @@ exports.postUpdateProfile = function(req, res, next) {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
exports.postUpdatePassword = function(req, res, next) {
|
exports.postUpdatePassword = function(req, res, next) {
|
||||||
if (!req.body.password) {
|
req.assert('password', 'Password cannot be blank').notEmpty();
|
||||||
req.flash('errors', { msg: 'Password cannot be blank.' });
|
req.assert('password', 'Password must be at least 4 characters long').len(4);
|
||||||
return res.redirect('/account');
|
req.assert('confirmPassword', 'Passwords do not match').equals(req.body.password);
|
||||||
}
|
|
||||||
|
|
||||||
if (req.body.password !== req.body.confirmPassword) {
|
var errors = req.validationErrors();
|
||||||
req.flash('errors', { msg: 'Passwords do not match.' });
|
|
||||||
|
if (errors) {
|
||||||
|
req.flash('errors', errors);
|
||||||
return res.redirect('/account');
|
return res.redirect('/account');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue