Files
authentication/app/controller/Insiders.js

55 lines
2.2 KiB
JavaScript
Raw Normal View History

'use strict';
const Controller = require('../core/base_controller');
const fileName = "Insiders";
class InsidersController 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.insiders.loginUser(name);
if(user == "error") {
this.setResponse(ctx, 500, '服务器错误', "none");
return;
}
if (user && 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: "insiders-manager",
client_secret: "insiders-manager",
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),
loginCode: result.headers.location.split('?')[1].split('&')[0].split('=')[1]
};
await ctx.service.insiders.loginStatus(user.dataValues.uid, 1);
this.setResponse(ctx, 200, '登录成功', "deconstruction", data);
} else {
2026-06-04 10:38:26 +08:00
const data = user ? user.dataValues.status == 2 ? { msg: '该账号已被封禁,请联系管理员申诉', code: 444 } : { msg: '登录失败', code: 404 } : { 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 = InsidersController;