|
@@ -1,11 +1,12 @@
|
|
|
'use strict';
|
|
|
const Controller = require('egg').Controller;
|
|
|
const { BusinessError, ErrorCode } = require('naf-core').Error;
|
|
|
+const moment = require('moment');
|
|
|
class YunjiuyeController extends Controller {
|
|
|
constructor(ctx) {
|
|
|
super(ctx);
|
|
|
this.service = this.ctx.service.yunjiuye;
|
|
|
-
|
|
|
+ this.yjyLoginKey = this.app.config.yjyLoginKey;
|
|
|
}
|
|
|
// http://127.0.0.1:7001/api/train/y/login?params=
|
|
|
async login() {
|
|
@@ -45,5 +46,32 @@ class YunjiuyeController extends Controller {
|
|
|
const url = await this.service.yLogout(encDataStr);
|
|
|
this.ctx.ok({ data: url });
|
|
|
}
|
|
|
+ // loading页设置完用户后走该接口,进行用户登录的登记
|
|
|
+ async loginSuccess() {
|
|
|
+ const body = this.ctx.request.body;
|
|
|
+ if (!body.id) throw new BusinessError(ErrorCode.BADPARAM, '缺少参数');
|
|
|
+ const redis = this.app.redis;
|
|
|
+ await redis.set(`${this.yjyLoginKey}${body.id}`, moment().format('YYYY-MM-DD HH:mm:ss'));
|
|
|
+ this.ctx.ok();
|
|
|
+ }
|
|
|
+ // 云就业主动注销时的函数
|
|
|
+ async toLogout() {
|
|
|
+ const pstr = this.ctx.request.querystring;
|
|
|
+ let params = pstr.replace('params=', '');
|
|
|
+ if (!params) throw new BusinessError(ErrorCode.BADPARAM, '缺少注销参数');
|
|
|
+ params = this.service.decryptData(params);
|
|
|
+ if (!params) throw new BusinessError(ErrorCode.BADPARAM, '参数解析失败');
|
|
|
+ const res = await this.service.checkUserIsConnect(params);
|
|
|
+ if (!res) throw new BusinessError(ErrorCode.USER_NOT_BIND, '用户未绑定,无法检测登录状态');
|
|
|
+ else {
|
|
|
+ const redis = this.app.redis;
|
|
|
+ const loginTime = await redis.get(`${this.yjyLoginKey}${res}`);
|
|
|
+ if (loginTime) {
|
|
|
+ await redis.del(`${this.yjyLoginKey}${res}`);
|
|
|
+ this.ctx.ok();
|
|
|
+ } else throw new BusinessError(ErrorCode.NOT_LOGIN, '用户未登录');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
module.exports = YunjiuyeController;
|