|
@@ -28,17 +28,19 @@ export class LoginRecordService {
|
|
|
if (!userInfo) return;
|
|
|
const user_id = get(userInfo, 'id', get(userInfo, '_id'));
|
|
|
if (!user_id) return;
|
|
|
+ const role = get(userInfo, 'role');
|
|
|
+ if (!role) return;
|
|
|
const last_time = dayjs().format(this.timeFormat);
|
|
|
const expire_time = dayjs()
|
|
|
.add(this.expire_step, 's')
|
|
|
.format(this.timeFormat);
|
|
|
const req = this.ctx.request;
|
|
|
const last_ip = get(req, 'header.x-forwarded-for', req.ip);
|
|
|
- const data: any = { token, last_time, expire_time, last_ip };
|
|
|
- const num = await this.model.count({ where: { user_id } });
|
|
|
+ const data: any = { token, last_time, expire_time, last_ip, role };
|
|
|
+ const num = await this.model.count({ where: { user_id, role } });
|
|
|
if (num > 0) {
|
|
|
// 有过登录记录,那就直接更新token,last_time,expire_time,last_ip就行
|
|
|
- const q1: any = { user_id }
|
|
|
+ const q1: any = { user_id, role }
|
|
|
await this.model.update(q1, data);
|
|
|
} else {
|
|
|
// 没有记录,那就创建
|
|
@@ -73,7 +75,9 @@ export class LoginRecordService {
|
|
|
if (!userInfo) return;
|
|
|
const user_id = get(userInfo, 'id', get(userInfo, '_id'));
|
|
|
if (!user_id) return;
|
|
|
- const q1: any = { user_id }
|
|
|
+ const role = get(userInfo, 'role')
|
|
|
+ if (!role) return
|
|
|
+ const q1: any = { user_id, role }
|
|
|
const data = await this.model.findOne({ where: q1 });
|
|
|
if (!data) throw new ServiceError(ErrorCode.NOT_LOGIN);
|
|
|
const utoken = get(data, 'token');
|