北斗应用技术培训报名系统
This commit is contained in:
182
app/controller/Exam.js
Normal file
182
app/controller/Exam.js
Normal file
@@ -0,0 +1,182 @@
|
||||
const Controller = require('../core/base_controller');
|
||||
|
||||
const fileName = "Exam";
|
||||
|
||||
class ExamController extends Controller {
|
||||
// 用户报名接口
|
||||
async application() {
|
||||
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 form = {
|
||||
user_uid: uid,
|
||||
exam_uid: this.decryptRequest(body.uid),
|
||||
exam_name: this.decryptRequest(body.exam_name),
|
||||
source: "个人",
|
||||
status: 0,
|
||||
pay_status: 0,
|
||||
result: "用户个人报名",
|
||||
created_at: new Date()
|
||||
};
|
||||
const result = await ctx.service.exam.application(uid, form);
|
||||
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 + "--" + "application";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 用户取消报名接口
|
||||
async cancelApplication() {
|
||||
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 exam_uid = this.decryptRequest(body.uid);
|
||||
const result = await ctx.service.exam.cancelApplication(uid, exam_uid);
|
||||
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 + "--" + "cancelApplication";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 用户查看所有考试接口
|
||||
async examList() {
|
||||
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 result = await ctx.service.exam.examList(uid, body);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
let examMsg = [];
|
||||
result.rows.forEach(element => {
|
||||
examMsg.push(element.dataValues);
|
||||
});
|
||||
const data = {
|
||||
examMsg,
|
||||
count: result.count
|
||||
};
|
||||
this.setResponse(ctx, 200, '操作成功', "deconstruction", data);
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '操作失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "examList";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 用户查看考试结果接口
|
||||
async gradesList() {
|
||||
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 result = await ctx.service.exam.gradesList(uid, body);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
let gradesMsg = [];
|
||||
result.rows.forEach(element => {
|
||||
gradesMsg.push(element.dataValues);
|
||||
});
|
||||
const data = {
|
||||
gradesMsg,
|
||||
count: result.count
|
||||
};
|
||||
this.setResponse(ctx, 200, '操作成功', "deconstruction", data);
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '操作失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "gradesList";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 用户查看报名历史接口
|
||||
async applicationList() {
|
||||
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 result = await ctx.service.exam.applicationList(uid, body);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
let applicationMsg = [];
|
||||
result.rows.forEach(element => {
|
||||
applicationMsg.push(element.dataValues);
|
||||
});
|
||||
const data = {
|
||||
applicationMsg,
|
||||
count: result.count
|
||||
};
|
||||
this.setResponse(ctx, 200, '操作成功', "deconstruction", data);
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '操作失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "applicationList";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ExamController;
|
||||
161
app/controller/System.js
Normal file
161
app/controller/System.js
Normal file
@@ -0,0 +1,161 @@
|
||||
const Controller = require('../core/base_controller');
|
||||
|
||||
const fileName = "System";
|
||||
|
||||
class SystemController extends Controller {
|
||||
// 系统获取考试信息接口
|
||||
async examMsg() {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const result = await ctx.service.system.examMsg();
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
this.setResponse(ctx, 200, '操作成功', "deconstruction", result);
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '操作失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "examMsg";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 比较身份证号
|
||||
async diffIdentityCard() {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const body = ctx.request.body;
|
||||
const identity_card = this.decryptRequest(body.identity_card);
|
||||
const type = this.decryptRequest(body.type);
|
||||
const data = this.decryptRequest(body.data);
|
||||
const uid = data == 'null' ? null : data.split('?')[0];
|
||||
const result = await ctx.service.system.diffIdentityCard(identity_card, type, uid);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (!result) {
|
||||
this.setResponse(ctx, 404, '该身份证号已注册', "none");
|
||||
} else {
|
||||
this.setResponse(ctx, 200, '验证通过', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "diffIdentityCard";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 比较邮箱
|
||||
async diffEmail() {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const body = ctx.request.body;
|
||||
const email = this.decryptRequest(body.email);
|
||||
const type = this.decryptRequest(body.type);
|
||||
const data = this.decryptRequest(body.data);
|
||||
const uid = data == 'null' ? null : data.split('?')[0];
|
||||
const result = await ctx.service.system.diffEmail(email, type, uid);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (!result) {
|
||||
this.setResponse(ctx, 404, '该邮箱已经注册', "none");
|
||||
} else {
|
||||
this.setResponse(ctx, 200, '验证通过', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "diffEmail";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 比较电话号码
|
||||
async diffPhone() {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const body = ctx.request.body;
|
||||
const phone = this.decryptRequest(body.phone);
|
||||
const type = this.decryptRequest(body.type);
|
||||
const data = this.decryptRequest(body.data);
|
||||
const uid = data == 'null' ? null : data.split('?')[0];
|
||||
const result = await ctx.service.system.diffPhone(phone, type, uid);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (!result) {
|
||||
this.setResponse(ctx, 404, '该手机号已注册', "none");
|
||||
} else {
|
||||
this.setResponse(ctx, 200, '验证通过', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "diffPhone";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 用户注册接口
|
||||
async registered() {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const body = ctx.request.body;
|
||||
const phone = this.decryptRequest(body.phone);
|
||||
// redis 存放短信验证码,过期时间为 10 分钟
|
||||
const redis = ctx.app.redis;
|
||||
const codeResult = await redis.get('db3').get(phone);
|
||||
if(!codeResult || JSON.parse(codeResult).status != '1') {
|
||||
this.setResponse(ctx, 333, '短信验证码错误', "none");
|
||||
return;
|
||||
}
|
||||
const salt = this.generateRandomString();
|
||||
const form = {
|
||||
uid: this.generateNumberString('E'),
|
||||
salt: this.encryptRequest(salt),
|
||||
password: this.shaForm(this.decryptRequest(body.password), salt),
|
||||
user_name: this.decryptRequest(body.user_name),
|
||||
identity_card: this.decryptRequest(body.identity_card),
|
||||
real_check: 0,
|
||||
workplace: this.decryptRequest(body.workplace),
|
||||
address: this.decryptRequest(body.address),
|
||||
phone: phone,
|
||||
email: this.decryptRequest(body.email),
|
||||
referrers: body.referrers ? this.decryptRequest(body.referrers) : null,
|
||||
status: 1,
|
||||
created_at: new Date(),
|
||||
updated_at: new Date(),
|
||||
login_status: 0,
|
||||
};
|
||||
const auditForm = {
|
||||
user_uid: form.uid,
|
||||
user_name: form.user_name,
|
||||
identity_card: form.identity_card,
|
||||
status: 0,
|
||||
created_at: new Date(),
|
||||
};
|
||||
const result = await ctx.service.system.registered(form, auditForm);
|
||||
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 + "--" + "registered";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = SystemController;
|
||||
180
app/controller/User.js
Normal file
180
app/controller/User.js
Normal file
@@ -0,0 +1,180 @@
|
||||
const Controller = require('../core/base_controller');
|
||||
|
||||
const fileName = "User";
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
class UserController extends Controller {
|
||||
// 信息完整性,合法性校验
|
||||
async checkInfo() {
|
||||
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 result = await ctx.service.user.checkInfo(uid);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result == 'OK') {
|
||||
this.setResponse(ctx, 200, '信息校验完成', "none");
|
||||
} else if (result == 'CNTEV') {
|
||||
this.setResponse(ctx, 303, '信息校验中', "none");
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '信息校验失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "checkInfo";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 用户照片是否存在判断
|
||||
async checkPhoto() {
|
||||
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 result = await ctx.service.user.checkPhoto(uid);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result.exist) {
|
||||
ctx.set('Cache-Control', 'no-cache, no-store, must-revalidate');
|
||||
ctx.set("Pragma", "no-cache");
|
||||
ctx.set("Expires", "0");
|
||||
this.setResponse(ctx, 200, '照片校验成功', "deconstruction", result);
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '照片校验失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "checkPhoto";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 身份证二要素核验
|
||||
async CNTEV() {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let rdmcode = await this.checkUid(ctx);
|
||||
if (!rdmcode) {
|
||||
this.setResponse(ctx, 401, 'token过期或错误', "none");
|
||||
return;
|
||||
}
|
||||
const { user_name, identity_card } = ctx.request.body;
|
||||
const result = await ctx.service.user.CNTEV(user_name, identity_card);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result == "1") {
|
||||
this.setResponse(ctx, 200, '身份证二要素核验成功', "none");
|
||||
} else if (result == "0") {
|
||||
const check = await ctx.app.redis.get('db3').get(identity_card);
|
||||
if (check == null) {
|
||||
ctx.curl('http://127.0.0.1:' + 8011 + '/CNTEV', {
|
||||
dataType: 'json',
|
||||
contentType: 'application/x-www-form-urlencoded',
|
||||
method: 'POST',
|
||||
timeout: 3000,
|
||||
data: {
|
||||
user_name,
|
||||
identity_card,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
await ctx.service.user.updateCNTEV(user_name, identity_card, JSON.parse(check).real_check);
|
||||
await ctx.app.redis.get('db3').del(identity_card);
|
||||
}
|
||||
this.setResponse(ctx, 303, '正在核验中', "none");
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '身份证二要素核验失败,请修改正确后等待管理员审核', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "CNTEV";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 用户上传照片
|
||||
async uploadPhoto() {
|
||||
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 { files } = ctx.request;
|
||||
const result = await ctx.service.user.uploadPhoto(uid, files);
|
||||
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 + "--" + "uploadPhoto";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
} finally {
|
||||
// 需要删除临时文件
|
||||
await ctx.cleanupRequestFiles();
|
||||
}
|
||||
}
|
||||
|
||||
// 用户找回密码
|
||||
async resetPassword() {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const body = ctx.request.body;
|
||||
// redis 存放短信验证码,过期时间为 10 分钟
|
||||
const phone = this.decryptRequest(body.phone);
|
||||
const redis = ctx.app.redis;
|
||||
const codeResult = await redis.get('db3').get(phone);
|
||||
if(!codeResult || JSON.parse(codeResult).status != '1') {
|
||||
this.setResponse(ctx, 333, '短信验证码错误', "none");
|
||||
return;
|
||||
}
|
||||
const salt = this.generateRandomString();
|
||||
const updateForm = {
|
||||
salt: this.encryptRequest(salt),
|
||||
password: this.shaForm(this.decryptRequest(body.password), salt)
|
||||
}
|
||||
const result = await ctx.service.user.resetPassword(updateForm, phone);
|
||||
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 + "--" + "resetPassword";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = UserController;
|
||||
Reference in New Issue
Block a user