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 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 {
|
2024-05-07 14:11:52 +00:00
|
|
|
response = 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:15:07 +00:00
|
|
|
let responseJson = response.json();
|
|
|
|
let retCode = responseJson.json().code;
|
2024-05-07 14:11:52 +00:00
|
|
|
if (retCode === 0) {
|
|
|
|
//登录成功
|
2024-05-07 14:15:07 +00:00
|
|
|
let retCredential = responseJson.data.Credential;
|
2024-05-07 14:11:52 +00:00
|
|
|
localStorage.setItem('auth', retCredential);
|
|
|
|
window.location.href = './config.html';
|
|
|
|
}
|
|
|
|
alert("登录失败,数据异常");
|
2024-05-07 13:17:31 +00:00
|
|
|
} catch (e) {
|
2024-05-07 14:11:52 +00:00
|
|
|
alert("登录失败");
|
2024-05-07 13:17:31 +00:00
|
|
|
console.log("请求异常",e);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
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>
|