北斗启航科技教育平台管理系统
This commit is contained in:
209
app/controller/ContestAccount.js
Normal file
209
app/controller/ContestAccount.js
Normal file
@@ -0,0 +1,209 @@
|
||||
const Controller = require('../core/base_controller');
|
||||
|
||||
const fileName = "ContestAccount";
|
||||
|
||||
class ContestAccountController extends Controller {
|
||||
// 管理系统导入竞赛账号信息
|
||||
async importAccount() {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let rdmcode = await this.checkUid(ctx);
|
||||
if (!rdmcode) {
|
||||
this.setResponse(ctx, 401, 'token过期或错误', "none");
|
||||
return;
|
||||
}
|
||||
const requestMsg = ctx.request.body.requestMsg;
|
||||
requestMsg.forEach(element => {
|
||||
const salt = this.generateRandomString();
|
||||
element.uid = this.generateNumberString('T');
|
||||
element.salt = this.encryptRequest(salt);
|
||||
element.contest_uid = this.decryptRequest(element.contest_uid);
|
||||
element.account_name = this.decryptRequest(element.account_name);
|
||||
element.password = this.shaForm('123456', salt);
|
||||
element.status = 0;
|
||||
element.created_at = new Date();
|
||||
element.login_status = 0;
|
||||
});
|
||||
const result = await ctx.service.contestAccount.importAccount(requestMsg);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
this.setResponse(ctx, 200, '操作成功', "none");
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '操作失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "importAccount";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统创建竞赛账号信息
|
||||
async addAccount() {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let rdmcode = await this.checkUid(ctx);
|
||||
if (!rdmcode) {
|
||||
this.setResponse(ctx, 401, 'token过期或错误', "none");
|
||||
return;
|
||||
}
|
||||
const requestMsg = ctx.request.body.requestMsg;
|
||||
requestMsg.forEach(element => {
|
||||
const salt = this.generateRandomString();
|
||||
element.uid = this.generateNumberString('T');
|
||||
element.salt = this.encryptRequest(salt);
|
||||
element.contest_uid = this.decryptRequest(element.contest_uid);
|
||||
element.account_name = this.decryptRequest(element.account_name);
|
||||
element.password = this.shaForm('123456', salt);
|
||||
element.status = 0;
|
||||
element.created_at = new Date();
|
||||
element.login_status = 0;
|
||||
});
|
||||
const result = await ctx.service.contestAccount.addAccount(requestMsg);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
this.setResponse(ctx, 200, '操作成功', "none");
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '操作失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "addAccount";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统查看竞赛账号信息
|
||||
async showAccount() {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let rdmcode = await this.checkUid(ctx);
|
||||
if (!rdmcode) {
|
||||
this.setResponse(ctx, 401, 'token过期或错误', "none");
|
||||
return;
|
||||
}
|
||||
const body = ctx.request.body;
|
||||
const result = await ctx.service.contestAccount.showAccount(body);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
let accountMsg = [];
|
||||
result.rows.forEach(element => {
|
||||
accountMsg.push(element.dataValues);
|
||||
});
|
||||
const data = {
|
||||
accountMsg,
|
||||
count: result.count
|
||||
};
|
||||
this.setResponse(ctx, 200, '操作成功', "deconstruction", data);
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '操作失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "showAccount";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统编辑竞赛账号信息
|
||||
async editAccount() {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let rdmcode = await this.checkUid(ctx);
|
||||
if (!rdmcode) {
|
||||
this.setResponse(ctx, 401, 'token过期或错误', "none");
|
||||
return;
|
||||
}
|
||||
const uid = JSON.parse(rdmcode).uid;
|
||||
const body = ctx.request.body;
|
||||
const { model, updateMsg, requestMsg } = body
|
||||
const modelType = this.decryptRequest(model);
|
||||
const result = await ctx.service.contestAccount.editAccount(uid, modelType, updateMsg, requestMsg);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
this.setResponse(ctx, 200, '操作成功', "none");
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '操作失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "editAccount";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统删除竞赛账号信息
|
||||
async delAccount() {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let rdmcode = await this.checkUid(ctx);
|
||||
if (!rdmcode) {
|
||||
this.setResponse(ctx, 401, 'token过期或错误', "none");
|
||||
return;
|
||||
}
|
||||
const uid = JSON.parse(rdmcode).uid;
|
||||
const body = ctx.request.body;
|
||||
const { model, password, requestMsg } = body
|
||||
const modelType = this.decryptRequest(model);
|
||||
const deCodePassword = this.decryptRequest(password);
|
||||
const result = await ctx.service.contestAccount.delAccount(uid, modelType, deCodePassword, requestMsg);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
this.setResponse(ctx, 200, '操作成功', "none");
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '操作失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "delAccount";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统重置竞赛账号密码
|
||||
async resetAccount() {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let rdmcode = await this.checkUid(ctx);
|
||||
if (!rdmcode) {
|
||||
this.setResponse(ctx, 401, 'token过期或错误', "none");
|
||||
return;
|
||||
}
|
||||
const uid = JSON.parse(rdmcode).uid;
|
||||
const { account_uid, password } = ctx.request.body;
|
||||
const accountUid = this.decryptRequest(account_uid);
|
||||
const resetPassword = this.decryptRequest(password);
|
||||
const result = await ctx.service.contestAccount.resetAccount(uid, accountUid, resetPassword);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
this.setResponse(ctx, 200, '操作成功', "none");
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '操作失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "resetAccount";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ContestAccountController;
|
||||
Reference in New Issue
Block a user