Created
March 31, 2017 18:46
-
-
Save ntotten/fa5c39b1621bc542db712a2b94f8db5b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
router.post('/change-password', middlewares.updateUserProfile, (req, res, next) => { | |
if (req.user.identities[0].isSocial) { | |
return sendError(400, 'Cannot update social account', next); | |
} | |
if (req.body.password !== req.body.confirm) { | |
return sendError(400, 'Password mismatch', next); | |
} | |
return auth0Utils.validatePassword(req.user, req.body.current) | |
.then(() => req.auth0.users.update({ id: req.user.id }, { password: req.body.password })) | |
.then(() => { | |
res.render('account/change-password', userUtils.addOptions(req, { success: true })); | |
}) | |
.catch((err) => { | |
if (err.status === 404) { | |
return res.render('account/change-password', userUtils.addOptions(req, { error: 'Wrong password' })); | |
} | |
return next(err); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment