📅  最后修改于: 2022-03-11 15:03:34.237000             🧑  作者: Mango
router.put('/password',verifyToken,UserController.updatePassword);
async updatePassword(req, res) {
const { user } = req;
const { currentPassword, newPassword } = req.body;
const matched = await user.comparePassword(currentPassword);
if (!matched) {
return res.warn('', req.__('PASSWORD_MATCH_FAILURE'));
}
const matcheAddedPassword = await user.comparePassword(newPassword);
if(matcheAddedPassword){
return res.warn('','Old password and new passowrd can not be same');
}
user.password = newPassword;
await user.save();
return res.success('', 'Password updated successfully.');
}