北斗应用技术培训报名系统
This commit is contained in:
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;
|
||||
Reference in New Issue
Block a user