|
@@ -36,6 +36,16 @@ class LoginService extends CrudService {
|
|
|
return await this.createJwt(res);
|
|
|
}
|
|
|
|
|
|
+ // 微信网页端登录(班主任,学生)
|
|
|
+ async openidLogin(data) {
|
|
|
+ const { openid, type } = data;
|
|
|
+ const res = await this.uModel.findOne({ openid, type });
|
|
|
+ if (!res) {
|
|
|
+ throw new BusinessError(ErrorCode.USER_NOT_EXIST);
|
|
|
+ }
|
|
|
+ return await this.createJwt(res);
|
|
|
+ }
|
|
|
+
|
|
|
// 创建登录Token
|
|
|
async createJwt({ _id, name, mobile, openid, type, uid, status }) {
|
|
|
const { secret, expiresIn = '1d', issuer = type } = this.config.jwt;
|
|
@@ -53,17 +63,35 @@ class LoginService extends CrudService {
|
|
|
} else if (type === '2') {
|
|
|
_userid = uid.toString();
|
|
|
const result = await this.schModel.findById(_userid);
|
|
|
+ if (!result) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到用户的角色信息');
|
|
|
res = { userid: _userid, code: result.code, name, type, id: _id, status };
|
|
|
} else if (type === '3') {
|
|
|
_userid = uid.toString();
|
|
|
const result = await this.tModel.findById(_userid);
|
|
|
+ if (!result) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到用户的角色信息');
|
|
|
res = { userid: _userid, schid: result.schid, schname: result.schname, name, subid: result.subid, type, id: _id, status };
|
|
|
} else if (type === '4') {
|
|
|
_userid = uid;
|
|
|
// console.log('进入查询--' + _userid);
|
|
|
const result = await this.stuModel.findById(_userid);
|
|
|
+ if (!result) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到用户的角色信息');
|
|
|
// console.log(result);
|
|
|
- res = { userid: _userid, schid: result.schid, schname: result.school_name, termid: result.termid, batchid: result.batchid, classid: result.classid, bedroomid: result.bedroomid, bedroom: result.bedroom, job: result.job, name, type, id: _id, status, planid: result.planid };
|
|
|
+ res = {
|
|
|
+ userid: _userid,
|
|
|
+ schid: result.schid,
|
|
|
+ schname: result.school_name,
|
|
|
+ termid: result.termid,
|
|
|
+ batchid: result.batchid,
|
|
|
+ classid: result.classid,
|
|
|
+ bedroomid: result.bedroomid,
|
|
|
+ bedroom: result.bedroom,
|
|
|
+ job: result.job,
|
|
|
+ name,
|
|
|
+ type,
|
|
|
+ id: _id,
|
|
|
+ status,
|
|
|
+ planid: result.planid,
|
|
|
+ };
|
|
|
// console.warn(res);
|
|
|
}
|
|
|
const token = await jwt.sign(res, secret, { expiresIn, issuer, subject });
|
|
@@ -82,7 +110,8 @@ class LoginService extends CrudService {
|
|
|
durable: true,
|
|
|
headers: {
|
|
|
openid,
|
|
|
- } };
|
|
|
+ },
|
|
|
+ };
|
|
|
if (mq) {
|
|
|
await mq.topic(ex, qrcode, 'scaned', parm);
|
|
|
}
|