first commit
This commit is contained in:
commit
3d5bc2b3b1
36
index.html
Normal file
36
index.html
Normal file
@ -0,0 +1,36 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-TW" xmlns="http://www.w3.org/1999/html" xmlns="http://www.w3.org/1999/html">
|
||||
<head>
|
||||
<!-- Required meta tags -->
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Welcome to nginx!</title>
|
||||
<style>
|
||||
html { color-scheme: light dark; }
|
||||
body { width: 35em; margin: 0 auto;
|
||||
font-family: Tahoma, Verdana, Arial, sans-serif; }
|
||||
</style>
|
||||
|
||||
<script language="javascript" type="text/javascript">
|
||||
const jwt = localStorage.getItem("jwtToken");
|
||||
if (!jwt) {
|
||||
window.location.href = "./login.html";
|
||||
}
|
||||
</script>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>Welcome to nginx!</h1>
|
||||
<p>If you see this page, the nginx web server is successfully installed and
|
||||
working. Further configuration is required.</p>
|
||||
|
||||
<p>For online documentation and support please refer to
|
||||
<a href="http://nginx.org/">nginx.org</a>.<br/>
|
||||
Commercial support is available at
|
||||
<a href="http://nginx.com/">nginx.com</a>.</p>
|
||||
|
||||
<p><em>Thank you for using nginx.</em></p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
53
login.html
Normal file
53
login.html
Normal file
@ -0,0 +1,53 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-TW" xmlns="http://www.w3.org/1999/html" xmlns="http://www.w3.org/1999/html">
|
||||
<head>
|
||||
<!-- Required meta tags -->
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
|
||||
<title>Login</title>
|
||||
</head>
|
||||
<body>
|
||||
<form id="login-form">
|
||||
|
||||
<p><input type="text" id="username" placeholder="Username"></p>
|
||||
<p><input type="password" id="password" placeholder="Password" autocomplete="true"></p>
|
||||
<p><button type="submit">Login</button></p>
|
||||
</form>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/axios@1.1.2/dist/axios.min.js"></script>
|
||||
<script language="javascript" type="text/javascript">
|
||||
document.getElementById('login-form').addEventListener('submit',
|
||||
function(event) {
|
||||
event.preventDefault(); // 阻止表单的默认提交行为
|
||||
|
||||
var username = document.getElementById('username').value;
|
||||
var password = document.getElementById('password').value;
|
||||
|
||||
// 执行登录请求
|
||||
login(username, password);
|
||||
});
|
||||
|
||||
function login(username, password) {
|
||||
// 发送登录请求
|
||||
axios.post('http://127.0.0.1:8080/api/v1/login', {
|
||||
account: username,
|
||||
password: password
|
||||
})
|
||||
.then(function(response) {
|
||||
var token = response.data.token; // 假设服务器返回一个名为"token"的字段
|
||||
|
||||
// 将JWT存储到本地(通常是使用localStorage)
|
||||
localStorage.setItem('jwtToken', token);
|
||||
|
||||
// 登录成功后,进行其他操作(例如重定向到受保护的页面)
|
||||
window.location.href = './index.html';
|
||||
})
|
||||
.catch(function(error) {
|
||||
console.error('登录失败:', error);
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Reference in New Issue
Block a user