[#1446] add change-password back in

This commit is contained in:
Tyler Renelle
2013-09-06 09:55:24 -04:00
parent c12de954a4
commit e6d61d1145
4 changed files with 48 additions and 2 deletions
+23
View File
@@ -184,6 +184,29 @@ api.resetPassword = function(req, res, next){
});
};
api.changePassword = function(req, res, next) {
var user = res.locals.user,
oldPassword = req.body.oldPassword,
newPassword = req.body.newPassword,
confirmNewPassword = req.body.confirmNewPassword;
if (newPassword != confirmNewPassword)
return res.json(500, {err: "Password & Confirm don't match"});
var salt = user.auth.local.salt,
hashed_old_password = utils.encryptPassword(oldPassword, salt),
hashed_new_password = utils.encryptPassword(newPassword, salt);
if (hashed_old_password !== user.auth.local.hashed_password)
return res.json(500, {err:"Old password doesn't match"});
user.auth.local.hashed_password = hashed_new_password;
user.save(function(err, saved){
if (err) res.json(500,{err:err});
res.send(200);
})
}
/*
Registers a new user. Only accepting username/password registrations, no Facebook
*/
+1
View File
@@ -8,5 +8,6 @@ router.post('/api/v1/register', auth.registerUser);
router.post('/api/v1/user/auth/local', auth.loginLocal);
router.post('/api/v1/user/auth/facebook', auth.loginFacebook);
router.post('/api/v1/user/reset-password', auth.resetPassword);
router.post('/api/v1/user/change-password', auth.auth, auth.changePassword);
module.exports = router;