From a3a40e1e74e7f17325e4c7e29f825c8223e5eaaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=89=8B=E7=93=9C=E4=B8=80=E5=8D=81=E9=9B=AA?= Date: Wed, 8 May 2024 20:10:33 +0800 Subject: [PATCH] feat: webui finish without auth --- src/webui/src/api/QQLogin.ts | 6 +++--- static/QQLogin.html | 33 +++++++++++++++++++++++++++++++-- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/src/webui/src/api/QQLogin.ts b/src/webui/src/api/QQLogin.ts index f4c1d7e7..6548894d 100644 --- a/src/webui/src/api/QQLogin.ts +++ b/src/webui/src/api/QQLogin.ts @@ -53,11 +53,11 @@ export const QQSetQuickLoginHandler: RequestHandler = async (req, res) => { }); return; } - let ret = await DataRuntime.getQQQuickLogin(uin); - if (!ret.result) { + const { result, message } = await DataRuntime.getQQQuickLogin(uin); + if (!result) { res.send({ code: -1, - message: ret.message + message: message }); return; } diff --git a/static/QQLogin.html b/static/QQLogin.html index b02419f6..f1e22f84 100644 --- a/static/QQLogin.html +++ b/static/QQLogin.html @@ -214,6 +214,27 @@ } return []; } + async function SetQuickLogin(uin, retCredential) { + let QQLoginResponse = await fetch('/api/QQLogin/SetQuickLogin', { + method: 'POST', + headers: { + 'Authorization': "Bearer " + retCredential, + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ + uin: uin + }) + }); + if (QQLoginResponse.status == 200) { + let QQLoginResponseJson = await QQLoginResponse.json(); + if (QQLoginResponseJson.code == 0) { + return { result: true, errMsg: "" }; + } else { + return { result: false, errMsg: QQLoginResponseJson.message }; + } + } + return { result: false, errMsg: "接口异常" };; + } //心跳轮询CheckQQLoginStatus 是否已经进入登录状态,如果为true进入./config.html async function HeartBeat() { let isLogined = await CheckQQLoginStatus(localStorage.getItem('auth')); @@ -240,8 +261,16 @@ qrcode.style.display = 'none'; }); - function selectAccount(accountName) { - alert(`Logging in with ${accountName}...`); + async function selectAccount(accountName) { + //alert(`Logging in with ${accountName}...`); + const { result, errMsg } = await SetQuickLogin(accountName, localStorage.getItem('auth')); + if (result) { + alert("登录成功即将跳转"); + window.location.href = './config.html'; + } else { + alert("登录失败," + errMsg); + } + //await (localStorage.getItem('auth')) document.getElementById('quick-login-options').classList.remove('show'); } document.getElementById('qrcode-login').addEventListener('click', function () {