明树Git Lab

Commit 13f4e8c1 authored by zengfanpei's avatar zengfanpei

update

parent 7ff0c0bc
...@@ -178,14 +178,29 @@ async function changePassword(req, res, next) { ...@@ -178,14 +178,29 @@ async function changePassword(req, res, next) {
try { try {
let user = req.user; let user = req.user;
let newPassword = req.body.newPassword; let newPassword = req.body.newPassword;
let oldPassword = req.body.oldPassword;
let dbUser = await userModule.findOne({_id: user._id});
if(!(dbUser && dbUser._id)) {
return res.sendError(errorMessage.loginError);
}
const check = utils.checkUserPassword({
reqPw: oldPassword,
salt: dbUser.salt,
userPw: dbUser.password,
});
if (!check) {
return res.sendError(errorMessage.loginError);
}
//更新密码
const { salt, passwordHash } = utils.saltHashPassword(newPassword); const { salt, passwordHash } = utils.saltHashPassword(newPassword);
const ret = await userModule.findOneAndUpdate({_id: user._id}, { const ret = await userModule.findOneAndUpdate({_id: user._id}, {
// ...req.body, // ...req.body,
salt, salt,
password: passwordHash password: passwordHash
}); });
await ioRedis.del(`token:${user.token}`) await ioRedis.del(`token:${user.token}`)
res.sendData(req.user); res.sendData({});
} catch (error) { } catch (error) {
next(error); next(error);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment