北斗启航科技教育平台登录系统
This commit is contained in:
60
app/controller/Contest.js
Normal file
60
app/controller/Contest.js
Normal file
@@ -0,0 +1,60 @@
|
||||
'use strict';
|
||||
|
||||
const Controller = require('../core/base_controller');
|
||||
|
||||
const fileName = "Contest";
|
||||
|
||||
class ContestController extends Controller {
|
||||
// 竞赛用户登录
|
||||
async login() {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const body = ctx.request.body;
|
||||
const name = this.decryptRequest(body.name);
|
||||
const password = this.decryptRequest(body.password);
|
||||
const user = await ctx.service.contest.loginUser(name);
|
||||
if(user == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
const client = await ctx.service.verify.loginClient(body.client_id);
|
||||
if(client == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (user && client && user.dataValues.status !== 2 && user.dataValues.password == this.shaForm(password, this.decryptRequest(user.dataValues.salt))) {
|
||||
const result = await ctx.curl('http://127.0.0.1:' + ctx.app.server.address().port + '/user/authorize', {
|
||||
dataType: 'json',
|
||||
contentType: 'application/x-www-form-urlencoded',
|
||||
method: 'POST',
|
||||
timeout: 3000,
|
||||
data: {
|
||||
state: 'xyz',
|
||||
response_type: 'code',
|
||||
username: user.dataValues.uid,
|
||||
password: password,
|
||||
client_id: client.dataValues.client_id,
|
||||
client_secret: client.dataValues.client_secret,
|
||||
redirect_uri: 'http://127.0.0.1:' + ctx.app.server.address().port + '/getToken/'
|
||||
},
|
||||
});
|
||||
const timestamp = new Date().getTime();
|
||||
const data = {
|
||||
data: this.encryptRequest(user.dataValues.uid + '?' + timestamp),
|
||||
redirect: client.dataValues.client_url + '?' + result.headers.location.split('?')[1].split('&')[0].split('=')[1]
|
||||
};
|
||||
await ctx.service.contest.loginStatus(user.dataValues.uid, 1);
|
||||
this.setResponse(ctx, 200, '登录成功', "deconstruction", data);
|
||||
} else {
|
||||
const data = user.dataValues.status == 2 ? { msg: '该账号已被封禁,请联系管理员申诉', code: 444 } : { msg: '登录失败', code: 404 };
|
||||
this.setResponse(ctx, 404, '登录失败', "deconstruction", data);
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "login";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ContestController;
|
||||
Reference in New Issue
Block a user