Skip to content
This repository has been archived by the owner on Aug 30, 2021. It is now read-only.

Commit

Permalink
Fix password validation error in change password
Browse files Browse the repository at this point in the history
  • Loading branch information
amoshaviv committed Jun 1, 2014
1 parent 5e3b1af commit 9db5e71
Showing 1 changed file with 37 additions and 31 deletions.
68 changes: 37 additions & 31 deletions app/controllers/users.server.controller.js
Expand Up @@ -140,45 +140,51 @@ exports.changePassword = function(req, res, next) {
var message = null;

if (req.user) {
User.findById(req.user.id, function(err, user) {
if (!err && user) {
if (user.authenticate(passwordDetails.currentPassword)) {
if (passwordDetails.newPassword === passwordDetails.verifyPassword) {
user.password = passwordDetails.newPassword;

user.save(function(err) {
if (err) {
return res.send(400, {
message: getErrorMessage(err)
});
} else {
req.login(user, function(err) {
if (err) {
res.send(400, err);
} else {
res.send({
message: 'Password changed successfully'
});
}
});
}
});
if (passwordDetails.newPassword) {
User.findById(req.user.id, function(err, user) {
if (!err && user) {
if (user.authenticate(passwordDetails.currentPassword)) {
if (passwordDetails.newPassword === passwordDetails.verifyPassword) {
user.password = passwordDetails.newPassword;

user.save(function(err) {
if (err) {
return res.send(400, {
message: getErrorMessage(err)
});
} else {
req.login(user, function(err) {
if (err) {
res.send(400, err);
} else {
res.send({
message: 'Password changed successfully'
});
}
});
}
});
} else {
res.send(400, {
message: 'Passwords do not match'
});
}
} else {
res.send(400, {
message: 'Passwords do not match'
message: 'Current password is incorrect'
});
}
} else {
res.send(400, {
message: 'Current password is incorrect'
message: 'User is not found'
});
}
} else {
res.send(400, {
message: 'User is not found'
});
}
});
});
} else {
res.send(400, {
message: 'Please provide a new password'
});
}
} else {
res.send(400, {
message: 'User is not signed in'
Expand Down

0 comments on commit 9db5e71

Please sign in to comment.