Skip to content

Instantly share code, notes, and snippets.

@ntotten
Created March 31, 2017 18:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ntotten/fa5c39b1621bc542db712a2b94f8db5b to your computer and use it in GitHub Desktop.
Save ntotten/fa5c39b1621bc542db712a2b94f8db5b to your computer and use it in GitHub Desktop.
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