|
@@ -27,7 +27,13 @@ class UserService extends CrudService {
|
|
|
const res = await this.model.create(newdata);
|
|
|
if (res) {
|
|
|
const url = this.ctx.app.config.axios.auth.baseUrl;
|
|
|
- const newdata = { name, phone: data.phone, passwd: password, uid: res.id, role: data.role };
|
|
|
+ const newdata = {
|
|
|
+ name,
|
|
|
+ phone: data.phone,
|
|
|
+ passwd: password,
|
|
|
+ uid: res.id,
|
|
|
+ role: data.role,
|
|
|
+ };
|
|
|
await this.ctx.curl(url, {
|
|
|
method: 'post',
|
|
|
headers: {
|
|
@@ -40,6 +46,20 @@ class UserService extends CrudService {
|
|
|
return res;
|
|
|
}
|
|
|
|
|
|
+ // 用户修改密码
|
|
|
+ async uppasswd(data) {
|
|
|
+ const { uid, newpasswd } = data;
|
|
|
+ assert(uid && newpasswd, '缺少部分信息项');
|
|
|
+ // 根据用户id查询其他用户表中是否存在相应数据
|
|
|
+ const user = await this.model.findById(uid, '+password');
|
|
|
+ // 如果用户不存在抛出异常
|
|
|
+ if (!user) {
|
|
|
+ throw new BusinessError(ErrorCode.USER_NOT_EXIST);
|
|
|
+ }
|
|
|
+ user.password = { secret: data.newpasswd };
|
|
|
+ await user.save();
|
|
|
+ }
|
|
|
+
|
|
|
async update({ id }, data) {
|
|
|
const user = await this.model.findById(id);
|
|
|
const { phone } = data;
|
|
@@ -97,11 +117,39 @@ class UserService extends CrudService {
|
|
|
}
|
|
|
|
|
|
// 创建登录Token
|
|
|
- async createJwt({ id, name, phone, is_qy, img_path, email, resume, major, office_phone, profession, role, status, columnid }) {
|
|
|
+ async createJwt({
|
|
|
+ id,
|
|
|
+ name,
|
|
|
+ phone,
|
|
|
+ is_qy,
|
|
|
+ img_path,
|
|
|
+ email,
|
|
|
+ resume,
|
|
|
+ major,
|
|
|
+ office_phone,
|
|
|
+ profession,
|
|
|
+ role,
|
|
|
+ status,
|
|
|
+ columnid,
|
|
|
+ }) {
|
|
|
const { secret, expiresIn = '1d', issuer } = this.config.jwt;
|
|
|
const subject = phone;
|
|
|
// const _userid = id;
|
|
|
- const res = { name, phone, is_qy, id, img_path, email, resume, major, office_phone, profession, role, status, columnid };
|
|
|
+ const res = {
|
|
|
+ name,
|
|
|
+ phone,
|
|
|
+ is_qy,
|
|
|
+ id,
|
|
|
+ img_path,
|
|
|
+ email,
|
|
|
+ resume,
|
|
|
+ major,
|
|
|
+ office_phone,
|
|
|
+ profession,
|
|
|
+ role,
|
|
|
+ status,
|
|
|
+ columnid,
|
|
|
+ };
|
|
|
const token = await jwt.sign(res, secret, { expiresIn, issuer, subject });
|
|
|
return token;
|
|
|
}
|