diff --git a/src/webui/src/router/QQLogin.ts b/src/webui/src/router/QQLogin.ts new file mode 100644 index 00000000..7bc7253e --- /dev/null +++ b/src/webui/src/router/QQLogin.ts @@ -0,0 +1,7 @@ +import { Router } from 'express'; +import { QQCheckLoginStatusHandler } from '../api/QQLogin'; + +const router = Router(); + +router.post('/CheckLoginStatus', QQCheckLoginStatusHandler); +export { router as QQLoginRouter }; \ No newline at end of file diff --git a/src/webui/src/router/index.ts b/src/webui/src/router/index.ts index 32541761..c6b6a41f 100644 --- a/src/webui/src/router/index.ts +++ b/src/webui/src/router/index.ts @@ -1,6 +1,7 @@ import { Router } from "express"; import { AuthHelper } from '../../src/helper/SignToken'; import { NextFunction, Request, Response } from 'express'; +import { QQLoginRouter } from "./QQLogin"; import { AuthRouter } from "./auth"; const router = Router(); export async function AuthApi(req: Request, res: Response, next: NextFunction) { @@ -45,4 +46,5 @@ router.all("/test", (req, res) => { }); }); router.use('/auth', AuthRouter);//挂载权限路由 +router.use('/QQLogin',QQLoginRouter); export { router as ALLRouter } \ No newline at end of file diff --git a/static/login.html b/static/login.html index 6689a26c..98214c22 100644 --- a/static/login.html +++ b/static/login.html @@ -85,24 +85,42 @@ let data = ""; try { - let response = await fetch('/api/auth/login', { + let loginResponse = await fetch('/api/auth/login', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ token: tokenInput.value }) }); - const responseJson = await response.json(); - let retCode = responseJson.code; + const loginResponseJson = await loginResponse.json(); + let retCode = loginResponseJson.code; if (retCode === 0) { //登录成功 - let retCredential = responseJson.data.Credential; + let retCredential = loginResponseJson.data.Credential; localStorage.setItem('auth', retCredential); - window.location.href = './config.html'; + let QQLoginResponse = await fetch('/api/QQLogin/CheckLoginStatus', { + method: 'POST', + headers: { + 'Authorization': "Bearer " + retCredential, + 'Content-Type': 'application/json' + } + }); + if (QQLoginResponse.status == 200) { + let QQLoginResponseJson = await QQLoginResponse.json(); + if (QQLoginResponseJson.code == 0) { + if (QQLoginResponseJson.data.isLogin) { + window.location.href = './config.html'; + } else { + window.location.href = './QQLogin.html'; + } + } + } + + alert("登录成功即将跳转"); } else { - console.log(responseJson.message); - alert(responseJson.message); + console.log(loginResponseJson.message); + alert(loginResponseJson.message); } } catch (e) {