|
@@ -24,30 +24,33 @@ class adminUserService extends Service {
|
|
|
throw new Error('添加失败');
|
|
|
}
|
|
|
}
|
|
|
- async update({ userName, phone, _id, roleList, state }) {
|
|
|
+ async update({ userName, phone, _id, roleList, state, password }) {
|
|
|
assert(_id, 'id不存在');
|
|
|
const { AdminUser: model } = this.ctx.model;
|
|
|
try {
|
|
|
- await model.findById(_id).update({ userName, phone, roleList, state });
|
|
|
+ const hash = crypto.createHmac('sha256', this.app.config.userSecret);
|
|
|
+ const pwd = hash.update(password).digest('hex');
|
|
|
+ await model.findById(_id).update({ userName, phone, roleList, state, password: pwd });
|
|
|
return { errmsg: '', errcode: 0 };
|
|
|
} catch (error) {
|
|
|
console.log(error);
|
|
|
throw new Error('修改失败');
|
|
|
}
|
|
|
}
|
|
|
- async pwdUpdate({ password, _id, confirmPwd }) {
|
|
|
- assert(_id, 'id不存在');
|
|
|
+ async pwdUpdate({ password, userName, confirmPwd }) {
|
|
|
+ console.log(password, userName, confirmPwd);
|
|
|
+ assert(userName, '用户名不存在');
|
|
|
const { AdminUser: model } = this.ctx.model;
|
|
|
const hash = crypto.createHmac('sha256', this.app.config.userSecret);
|
|
|
const cpwd = hash.update(confirmPwd).digest('hex');
|
|
|
try {
|
|
|
- const res = await model.findById(_id);
|
|
|
+ const res = await model.findOne({ userName });
|
|
|
if (res.password !== cpwd) {
|
|
|
return { errmsg: '原密码错误', errcode: -2003 };
|
|
|
}
|
|
|
const hash = crypto.createHmac('sha256', this.app.config.userSecret);
|
|
|
const pwd = hash.update(password).digest('hex');
|
|
|
- await model.findByIdAndUpdate(_id, { password: pwd });
|
|
|
+ await model.findByIdAndUpdate(res._id, { password: pwd });
|
|
|
return { errmsg: '', errcode: 0 };
|
|
|
} catch (error) {
|
|
|
throw new Error('修改失败');
|