NapCatQQ/static/login.html

136 lines
4.5 KiB
HTML
Raw Normal View History

2024-05-05 13:29:09 +00:00
<!DOCTYPE html>
2024-05-05 14:49:56 +00:00
<html lang="en">
2024-05-05 13:29:09 +00:00
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
2024-05-07 13:17:31 +00:00
<title>WebUi - Login</title>
2024-05-05 14:49:56 +00:00
<style>
body {
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-color: #f0f2f5;
}
.login-container {
padding: 20px;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
background-color: white;
max-width: 400px;
min-width: 300px;
position: relative;
}
2024-05-07 13:17:31 +00:00
.input-group {
2024-05-05 14:49:56 +00:00
margin-bottom: 20px;
}
2024-05-07 13:17:31 +00:00
input[type="text"] {
width: 90%;
padding: 10px;
2024-05-05 14:49:56 +00:00
font-size: 16px;
2024-05-07 13:17:31 +00:00
border: 1px solid #ccc;
border-radius: 5px;
2024-05-06 04:36:02 +00:00
}
2024-05-05 14:49:56 +00:00
button {
width: 100%;
padding: 10px;
background-color: #007BFF;
color: white;
border: none;
cursor: pointer;
transition: all 0.3s;
}
button:hover {
background-color: #0056b3;
}
2024-05-07 13:17:31 +00:00
.error-message {
color: red;
margin-top: 5px;
2024-05-06 04:36:02 +00:00
}
2024-05-05 14:49:56 +00:00
</style>
2024-05-05 13:29:09 +00:00
</head>
2024-05-05 14:49:56 +00:00
2024-05-05 13:29:09 +00:00
<body>
2024-05-05 14:49:56 +00:00
<div class="login-container">
2024-05-07 13:17:31 +00:00
<h2>WebUi Login</h2>
<form id="token-form" onsubmit="event.preventDefault(); submitToken();">
<div class="input-group">
<label for="token-input">Enter Token:</label>
<input type="text" id="token-input" required>
</div>
<p class="error-message hidden" id="error-message"></p>
<button type="submit">Login</button>
</form>
2024-05-05 14:49:56 +00:00
</div>
<script>
2024-05-07 14:44:55 +00:00
//待封装整理
2024-05-07 13:17:31 +00:00
async function submitToken() {
const tokenInput = document.getElementById('token-input');
const errorMessage = document.getElementById('error-message');
if (tokenInput.value.trim() === '') {
errorMessage.textContent = 'Please enter a token.';
errorMessage.classList.remove('hidden');
} else {
errorMessage.textContent = '';
errorMessage.classList.add('hidden');
//请求 /api/login post token
let data = "";
try {
let loginResponse = await fetch('../api/auth/login', {
2024-05-07 13:17:31 +00:00
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ token: tokenInput.value })
});
2024-05-07 14:35:15 +00:00
const loginResponseJson = await loginResponse.json();
let retCode = loginResponseJson.code;
2024-05-07 14:11:52 +00:00
if (retCode === 0) {
//登录成功
2024-05-07 14:35:15 +00:00
let retCredential = loginResponseJson.data.Credential;
2024-05-07 14:11:52 +00:00
localStorage.setItem('auth', retCredential);
let QQLoginResponse = await fetch('../api/QQLogin/CheckLoginStatus', {
2024-05-07 14:35:15 +00:00
method: 'POST',
headers: {
'Authorization': "Bearer " + retCredential,
'Content-Type': 'application/json'
}
});
if (QQLoginResponse.status == 200) {
let QQLoginResponseJson = await QQLoginResponse.json();
if (QQLoginResponseJson.code == 0) {
2024-05-08 07:07:20 +00:00
//alert(QQLoginResponseJson.data.isLogin.toString());
2024-05-07 14:35:15 +00:00
if (QQLoginResponseJson.data.isLogin) {
window.location.href = './config.html';
} else {
window.location.href = './QQLogin.html';
}
}
}
2024-05-07 14:26:17 +00:00
alert("登录成功即将跳转");
} else {
2024-05-07 14:35:15 +00:00
console.log(loginResponseJson.message);
alert(loginResponseJson.message);
2024-05-07 14:11:52 +00:00
}
2024-05-07 14:26:17 +00:00
2024-05-07 13:17:31 +00:00
} catch (e) {
2024-05-07 14:11:52 +00:00
alert("登录失败");
2024-05-07 14:26:17 +00:00
console.log("请求异常", e);
2024-05-07 13:17:31 +00:00
}
}
2024-05-05 14:49:56 +00:00
}
</script>
2024-05-05 13:29:09 +00:00
</body>
2024-05-05 14:49:56 +00:00
2024-05-05 13:29:09 +00:00
</html>