| Your Name | 695f6a6 | 2025-05-17 00:58:04 +0800 | [diff] [blame] | 1 | <!-- 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 Name | 292c25d | 2025-05-25 01:21:44 +0800 | [diff] [blame^] | 11 | <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 Name | 695f6a6 | 2025-05-17 00:58:04 +0800 | [diff] [blame] | 19 | <button type="submit">登录</button> |
| 20 | </form> |
| Your Name | 292c25d | 2025-05-25 01:21:44 +0800 | [diff] [blame^] | 21 | + <p><a href="reset.html">忘记密码?</a></p> |
| 22 | |
| Your Name | 695f6a6 | 2025-05-17 00:58:04 +0800 | [diff] [blame] | 23 | <script> |
| Your Name | 292c25d | 2025-05-25 01:21:44 +0800 | [diff] [blame^] | 24 | 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 Name | 695f6a6 | 2025-05-17 00:58:04 +0800 | [diff] [blame] | 34 | }); |
| Your Name | 292c25d | 2025-05-25 01:21:44 +0800 | [diff] [blame^] | 35 | 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 Name | 695f6a6 | 2025-05-17 00:58:04 +0800 | [diff] [blame] | 43 | </script> |
| 44 | </body> |
| 45 | </html> |