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

Commit

Permalink
Update Dev Depenedencies + Password Change Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
amoshaviv committed Mar 30, 2014
1 parent 12cb3bf commit c0a7c05
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 36 deletions.
74 changes: 40 additions & 34 deletions app/controllers/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ exports.update = function(req, res) {
user = _.extend(user, req.body);
user.updated = Date.now();
user.displayName = user.firstName + ' ' + user.lastName;

user.save(function(err) {
if (err) {
return res.send(400, {
Expand Down Expand Up @@ -129,50 +129,56 @@ exports.changePassword = function(req, res, next) {
var passwordDetails = req.body;
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.currentPassword) {
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'
});
}
});
}
});

} 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: 'User is not signed in'
});
}
} else {
res.send(400, {
message: 'User is not signed in'
message: 'Please fill current password'
});
}
};
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
"grunt-cli": "~0.1.13"
},
"devDependencies": {
"supertest": "~0.9.0",
"should": "~3.1.3",
"supertest": "~0.10.0",
"should": "~3.2.0",
"grunt-env": "~0.4.1",
"grunt-node-inspector": "~0.1.3",
"grunt-contrib-watch": "~0.6.1",
Expand Down

0 comments on commit c0a7c05

Please sign in to comment.