blob: f7d02c7788d0bd471b75285b88048f657b60dc75 [file] [log] [blame]
Your Name695f6a62025-05-17 00:58:04 +08001<!-- src/main/resources/static/login.html -->
2<!DOCTYPE html>
3<html lang="zh-CN">
4<head>
5 <meta charset="UTF-8">
6 <title>登录</title>
7</head>
8<body>
9<h2>用户登录</h2>
10<form id="loginForm">
Your Name292c25d2025-05-25 01:21:44 +080011 <div>
12 <label>邮箱:</label>
13 <input type="email" name="email" required>
14 </div>
15 <div>
16 <label>密码:</label>
17 <input type="password" name="password" required>
18 </div>
Your Name695f6a62025-05-17 00:58:04 +080019 <button type="submit">登录</button>
20</form>
Your Name292c25d2025-05-25 01:21:44 +080021+ <p><a href="reset.html">忘记密码?</a></p>
22
Your Name695f6a62025-05-17 00:58:04 +080023<script>
Your Name292c25d2025-05-25 01:21:44 +080024 document.getElementById('loginForm').addEventListener('submit', async e => {
25 e.preventDefault();
26 const data = {
27 email: e.target.email.value,
28 password: e.target.password.value
29 };
30 const res = await fetch('/login', {
31 method: 'POST',
32 headers: { 'Content-Type': 'application/json' },
33 body: JSON.stringify(data)
Your Name695f6a62025-05-17 00:58:04 +080034 });
Your Name292c25d2025-05-25 01:21:44 +080035 const json = await res.json();
36 if (res.ok && json.code === 0) {
37 localStorage.setItem('token', json.data);
38 window.location.href = 'home.html';
39 } else {
40 alert(json.msg || json.error);
41 }
42 });
Your Name695f6a62025-05-17 00:58:04 +080043</script>
44</body>
45</html>