Simplify the password change logic

We now can use verifyPassword and this makes
user.changePassword() route obsolete
This commit is contained in:
Johannes Zellner
2016-04-17 19:17:01 +02:00
parent 87dcf42c7e
commit 18f3733d6e
5 changed files with 26 additions and 64 deletions
+1 -2
View File
@@ -69,9 +69,8 @@ function changePassword(req, res, next) {
if (req.user.tokenType !== tokendb.TYPE_USER) return next(new HttpError(403, 'Token type not allowed'));
user.changePassword(req.user.username, req.body.password, req.body.newPassword, function (error) {
user.setPassword(req.user.id, req.body.newPassword, function (error) {
if (error && error.reason === UserError.BAD_PASSWORD) return next(new HttpError(400, error.message));
if (error && error.reason === UserError.WRONG_PASSWORD) return next(new HttpError(403, 'Wrong password'));
if (error && error.reason === UserError.NOT_FOUND) return next(new HttpError(403, 'Wrong password'));
if (error) return next(new HttpError(500, error));