|
@@ -2,7 +2,7 @@ import { Config, Inject, Provide } from '@midwayjs/core';
|
|
import { JwtService } from '@midwayjs/jwt';
|
|
import { JwtService } from '@midwayjs/jwt';
|
|
import { Context } from '@midwayjs/koa';
|
|
import { Context } from '@midwayjs/koa';
|
|
import { get } from 'lodash';
|
|
import { get } from 'lodash';
|
|
-import { FrameworkErrorEnum, LoginError } from '../error/login.error';
|
|
+import { ServiceError, ErrorCode } from '../error/service.error';
|
|
import * as Crypto from 'crypto-js';
|
|
import * as Crypto from 'crypto-js';
|
|
import { RedisService } from '@midwayjs/redis';
|
|
import { RedisService } from '@midwayjs/redis';
|
|
|
|
|
|
@@ -30,9 +30,9 @@ export class SingleSignOnService {
|
|
const data = this.jwtService.decodeSync(token);
|
|
const data = this.jwtService.decodeSync(token);
|
|
if (data) user = data;
|
|
if (data) user = data;
|
|
}
|
|
}
|
|
- if (!user) throw new LoginError(FrameworkErrorEnum.NOT_LOGIN);
|
|
+ if (!user) throw new ServiceError(ErrorCode.NOT_LOGIN);
|
|
const { _id, role, login_code } = user;
|
|
const { _id, role, login_code } = user;
|
|
- if (!login_code) throw new LoginError(FrameworkErrorEnum.NOT_LOGIN);
|
|
+ if (!login_code) throw new ServiceError(ErrorCode.NOT_LOGIN);
|
|
|
|
|
|
const decodeResult = Crypto.AES.decrypt(login_code, this.jwtSecret);
|
|
const decodeResult = Crypto.AES.decrypt(login_code, this.jwtSecret);
|
|
const decode = Crypto.enc.Utf8.stringify(decodeResult).toString();
|
|
const decode = Crypto.enc.Utf8.stringify(decodeResult).toString();
|
|
@@ -43,14 +43,13 @@ export class SingleSignOnService {
|
|
const rediskey = `${this.loginSign}:${role}:${_id}`;
|
|
const rediskey = `${this.loginSign}:${role}:${_id}`;
|
|
|
|
|
|
const redisCode = await this.redisService.get(rediskey);
|
|
const redisCode = await this.redisService.get(rediskey);
|
|
- if (!redisCode)
|
|
+ if (!redisCode) throw new ServiceError(ErrorCode.ACCOUNT_HAS_EXPIRED);
|
|
- throw new LoginError(FrameworkErrorEnum.ACCOUNT_HAS_EXPIRED);
|
|
|
|
|
|
|
|
if (code === redisCode) {
|
|
if (code === redisCode) {
|
|
|
|
|
|
await this.redisService.expire(rediskey, this.jwtExpiresIn);
|
|
await this.redisService.expire(rediskey, this.jwtExpiresIn);
|
|
} else {
|
|
} else {
|
|
- throw new LoginError(FrameworkErrorEnum.ACCOUNT_LOGGED_IN_ELESWHERE);
|
|
+ throw new ServiceError(ErrorCode.ACCOUNT_LOGGED_IN_ELESWHERE);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|