|
@@ -19,7 +19,7 @@ class LoginService extends CrudService {
|
|
|
|
|
|
// 用户登录
|
|
// 用户登录
|
|
async login(data) {
|
|
async login(data) {
|
|
- const { phone, passwd, roomId } = data;
|
|
|
|
|
|
+ const { phone, passwd, roomid } = data;
|
|
// 根据用户输入的手机号查询其他用户表中是否存在相应数据
|
|
// 根据用户输入的手机号查询其他用户表中是否存在相应数据
|
|
const user = await this.model.findOne({ phone });
|
|
const user = await this.model.findOne({ phone });
|
|
// 如果用户不存在抛出异常
|
|
// 如果用户不存在抛出异常
|
|
@@ -37,9 +37,9 @@ class LoginService extends CrudService {
|
|
throw new BusinessError(ErrorCode.ACCESS_DENIED);
|
|
throw new BusinessError(ErrorCode.ACCESS_DENIED);
|
|
}
|
|
}
|
|
let type = '0';
|
|
let type = '0';
|
|
- let roomid = '';
|
|
|
|
- if (roomId) {
|
|
|
|
- const room = await this.roommodel.findOne({ name: roomId });
|
|
|
|
|
|
+ const roomid_ = '';
|
|
|
|
+ if (roomid) {
|
|
|
|
+ const room = await this.roommodel.findOne({ name: roomid });
|
|
if (!room) {
|
|
if (!room) {
|
|
throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '房间号不存在');
|
|
throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '房间号不存在');
|
|
}
|
|
}
|
|
@@ -63,7 +63,7 @@ class LoginService extends CrudService {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
user.menus = JSON.stringify(_menus);
|
|
user.menus = JSON.stringify(_menus);
|
|
- const newdata = { ...JSON.parse(JSON.stringify(user)), type, roomid, roomname: roomId };
|
|
|
|
|
|
+ const newdata = { ...JSON.parse(JSON.stringify(user)), type, roomid_, roomname: roomid };
|
|
const token = await this.createJwt(newdata);
|
|
const token = await this.createJwt(newdata);
|
|
await this.app.redis.set(key, token, 'EX', 60 * 60 * 24);
|
|
await this.app.redis.set(key, token, 'EX', 60 * 60 * 24);
|
|
return { key };
|
|
return { key };
|
|
@@ -77,10 +77,10 @@ class LoginService extends CrudService {
|
|
}
|
|
}
|
|
|
|
|
|
// 创建登录Token
|
|
// 创建登录Token
|
|
- async createJwt({ id, name, uid, phone, role, menus, remark, openid, deptname, type, roroomid, roomname }) {
|
|
|
|
|
|
+ async createJwt({ id, name, uid, phone, role, menus, remark, openid, deptname, type, roomid, roomname }) {
|
|
const { secret, expiresIn = '1d', issuer = role } = this.config.jwt;
|
|
const { secret, expiresIn = '1d', issuer = role } = this.config.jwt;
|
|
const subject = phone;
|
|
const subject = phone;
|
|
- const res = { id, uid, name, phone, role, menus, openid, remark, deptname, type, roroomid, roomname };
|
|
|
|
|
|
+ const res = { id, uid, name, phone, role, menus, openid, remark, deptname, type, roomid, roomname };
|
|
const token = await jwt.sign(res, secret, { expiresIn, issuer, subject });
|
|
const token = await jwt.sign(res, secret, { expiresIn, issuer, subject });
|
|
return token;
|
|
return token;
|
|
}
|
|
}
|