From 471da4f3b1acda1571d11b362fea88e97ac9e6e2 Mon Sep 17 00:00:00 2001 From: zyc404 Date: Sun, 15 Oct 2023 17:33:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=94=85=E5=B7=B4=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/modules/user.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/server/modules/user.js b/server/modules/user.js index 7458805..d5e3d47 100644 --- a/server/modules/user.js +++ b/server/modules/user.js @@ -6,12 +6,26 @@ async function User(fastify, options) { // 登录 fastify.post('/login', async (request, reply) => { const body = request.body || {} + let guobaLoginService + let guobaAPI = '' + try { + let { LoginService } = await import('../../../../guoba-plugin/server/service/both/LoginService.js') + let { getAllWebAddress } = await import('../../../../guoba-plugin/utils/common.js') + guobaLoginService = new LoginService() + guobaAPI = await getAllWebAddress().remote + } + catch (err) { + guobaLoginService = { + signToken: () => {return null} + } + } if (body.qq && body.passwd) { const token = randomString(32) if (body.qq == getUin() && await redis.get('CHATGPT:ADMIN_PASSWD') == body.passwd) { + const guobaToken = await guobaLoginService.signToken(body.qq) AddUser({ user: body.qq, token: token, autho: 'admin' }) reply.setCookie('token', token, { path: '/' }) - reply.send({ login: true, autho: 'admin', token: token }) + reply.send({ login: true, autho: 'admin', token: token, guobaToken: guobaToken, guoba: guobaAPI }) } else { const user = await getUserData(body.qq) if (user.passwd != '' && user.passwd === body.passwd) { @@ -26,9 +40,10 @@ async function User(fastify, options) { const token = randomString(32) const opt = await redis.get(`CHATGPT:SERVER_QUICK`) if (opt && body.otp == opt) { + const guobaToken = await guobaLoginService.signToken(getUin()) AddUser({ user: getUin(), token: token, autho: 'admin' }) reply.setCookie('token', token, { path: '/' }) - reply.send({ login: true, autho: 'admin', token: token, user: getUin() }) + reply.send({ login: true, autho: 'admin', token: token, user: getUin(), guobaToken: guobaToken, guoba: guobaAPI }) } else { reply.send({ login: false, err: `快捷登录代码错误,请检查后重试` }) }