Changed updatePassword controller validation to use express-validator instead of custom if statements

pull/2/head
Sahat Yalkabov 2014-02-01 03:39:11 -05:00
parent c0e1a1129a
commit 7396a6d7ab
1 changed files with 7 additions and 6 deletions

View File

@ -141,13 +141,14 @@ exports.postUpdateProfile = function(req, res, next) {
*/
exports.postUpdatePassword = function(req, res, next) {
if (!req.body.password) {
req.flash('errors', { msg: 'Password cannot be blank.' });
return res.redirect('/account');
}
req.assert('password', 'Password cannot be blank').notEmpty();
req.assert('password', 'Password must be at least 4 characters long').len(4);
req.assert('confirmPassword', 'Passwords do not match').equals(req.body.password);
if (req.body.password !== req.body.confirmPassword) {
req.flash('errors', { msg: 'Passwords do not match.' });
var errors = req.validationErrors();
if (errors) {
req.flash('errors', errors);
return res.redirect('/account');
}