first commit
This commit is contained in:
+53
@@ -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>
|
||||
Reference in New Issue
Block a user