北斗启航科技教育平台登录系统

This commit is contained in:
2026-03-27 17:50:18 +08:00
commit bdc25653a4
215 changed files with 5299 additions and 0 deletions

133
app/service/Insiders.js Normal file
View File

@@ -0,0 +1,133 @@
'use strict';
const Service = require('../core/base_service');
const fileName = "Insiders";
const { Op } = require('sequelize');
class InsidersService extends Service {
async loginUser(name) {
const { ctx } = this;
try {
const where = { name };
const result = await ctx.model3.Insiders.findOne({ where });
return result || false;
} catch (error) {
const blockName = fileName + "--" + "loginUser";
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
return 'error';
}
}
async uidfinder(uid) {
const { ctx } = this;
try {
const where = { uid };
const result = await ctx.model3.Insiders.findOne({ where });
return result || false;
} catch (error) {
const blockName = fileName + "--" + "uidfinder";
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
return 'error';
}
}
async getUser(uid) {
const { ctx } = this;
try {
const attributes = ['status', 'role', 'name', 'department'];
const where = { uid };
const result = await ctx.model3.Insiders.findOne({ attributes, where });
return result || false;
} catch (error) {
const blockName = fileName + "--" + "getUser";
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
return 'error';
}
}
async editUser(userMsg, uid) {
const { ctx } = this;
try {
const where = { uid };
const result = await ctx.model3.Insiders.update(userMsg, { where });
return result[0] == 0 ? false : result;
} catch (error) {
const blockName = fileName + "--" + "editUser";
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
return 'error';
}
}
async changePassword(uid, oldPassword, newPassword) {
const { ctx } = this;
try {
const where = { uid };
const salt = this.generateRandomString();
const setPassword = this.shaForm(newPassword, salt);
const result = await ctx.model3.Insiders.findOne({ where });
if(!result || result.dataValues.status == 2 || result.dataValues.password !== this.shaForm(oldPassword, this.decryptRequest(result.dataValues.salt))) return false;
const resultList = await ctx.model3.Insiders.update({ salt: this.encryptRequest(salt), status: 1, password: setPassword }, { where });
return resultList[0] == 0 ? false : resultList;
} catch (error) {
const blockName = fileName + "--" + "changePassword";
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
return 'error';
}
}
async resetPassword(uid, modelType, defaultPassword, password, body, resetType) {
const { ctx } = this;
try {
const result = await ctx.model3.Insiders.findOne({ where: { uid, role: [6, 9] } });
if(!result || result.dataValues.status == 2 || result.dataValues.password !== this.shaForm(password, this.decryptRequest(result.dataValues.salt))) return false;
const salt = this.generateRandomString();
if(defaultPassword == "") {
defaultPassword = '123456';
}
const originPassword = this.shaForm(defaultPassword, salt);
let where = {}, role;
if(result.dataValues.password == 9) {
role = { [Op.not]: [9] };
} else {
role = { [Op.not]: [6, 9] };
}
if(modelType == "single") {
where = { role, ...body };
} else if (modelType == "multiple") {
let account_name = [], user_name = [], phone = [];
for (const key in body) {
body[key].forEach(element => {
account_name.push(element.account_name);
user_name.push(element.user_name);
phone.push(element.phone);
});
}
where = { role, account_name, user_name, phone };
} else if (modelType == "all") {
where = { role };
}
const resetList = await ctx.model3.Insiders.update({ salt: this.encryptRequest(salt), status: 0, password: originPassword }, { where });
return resetList.length == 0 ? false : resetList;
} catch (error) {
const blockName = fileName + "--" + "resetPassword";
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
return 'error';
}
}
async loginStatus(uid, login_status) {
const { ctx } = this;
try {
const where = { uid };
await ctx.model.BSide.update({ login_status }, { where });
} catch (error) {
const blockName = fileName + "--" + "loginStatus";
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
return 'error';
}
}
}
module.exports = InsidersService;