mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2024-11-21 09:36:35 +00:00
feat:QQLogin Api
This commit is contained in:
parent
1c7d9c3513
commit
dedd0be352
7
src/webui/src/router/QQLogin.ts
Normal file
7
src/webui/src/router/QQLogin.ts
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import { Router } from 'express';
|
||||||
|
import { QQCheckLoginStatusHandler } from '../api/QQLogin';
|
||||||
|
|
||||||
|
const router = Router();
|
||||||
|
|
||||||
|
router.post('/CheckLoginStatus', QQCheckLoginStatusHandler);
|
||||||
|
export { router as QQLoginRouter };
|
@ -1,6 +1,7 @@
|
|||||||
import { Router } from "express";
|
import { Router } from "express";
|
||||||
import { AuthHelper } from '../../src/helper/SignToken';
|
import { AuthHelper } from '../../src/helper/SignToken';
|
||||||
import { NextFunction, Request, Response } from 'express';
|
import { NextFunction, Request, Response } from 'express';
|
||||||
|
import { QQLoginRouter } from "./QQLogin";
|
||||||
import { AuthRouter } from "./auth";
|
import { AuthRouter } from "./auth";
|
||||||
const router = Router();
|
const router = Router();
|
||||||
export async function AuthApi(req: Request, res: Response, next: NextFunction) {
|
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('/auth', AuthRouter);//挂载权限路由
|
||||||
|
router.use('/QQLogin',QQLoginRouter);
|
||||||
export { router as ALLRouter }
|
export { router as ALLRouter }
|
@ -85,24 +85,42 @@
|
|||||||
let data = "";
|
let data = "";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let response = await fetch('/api/auth/login', {
|
let loginResponse = await fetch('/api/auth/login', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
},
|
},
|
||||||
body: JSON.stringify({ token: tokenInput.value })
|
body: JSON.stringify({ token: tokenInput.value })
|
||||||
});
|
});
|
||||||
const responseJson = await response.json();
|
const loginResponseJson = await loginResponse.json();
|
||||||
let retCode = responseJson.code;
|
let retCode = loginResponseJson.code;
|
||||||
if (retCode === 0) {
|
if (retCode === 0) {
|
||||||
//登录成功
|
//登录成功
|
||||||
let retCredential = responseJson.data.Credential;
|
let retCredential = loginResponseJson.data.Credential;
|
||||||
localStorage.setItem('auth', retCredential);
|
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("登录成功即将跳转");
|
alert("登录成功即将跳转");
|
||||||
} else {
|
} else {
|
||||||
console.log(responseJson.message);
|
console.log(loginResponseJson.message);
|
||||||
alert(responseJson.message);
|
alert(loginResponseJson.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user