| <!-- src/main/resources/static/login.html --> |
| <!DOCTYPE html> |
| <html lang="zh-CN"> |
| <head> |
| <meta charset="UTF-8"> |
| <title>登录</title> |
| </head> |
| <body> |
| <h2>用户登录</h2> |
| <form id="loginForm"> |
| <div> |
| <label>邮箱:</label> |
| <input type="email" name="email" required> |
| </div> |
| <div> |
| <label>密码:</label> |
| <input type="password" name="password" required> |
| </div> |
| <button type="submit">登录</button> |
| </form> |
| + <p><a href="reset.html">忘记密码?</a></p> |
| |
| <script> |
| document.getElementById('loginForm').addEventListener('submit', async e => { |
| e.preventDefault(); |
| const data = { |
| email: e.target.email.value, |
| password: e.target.password.value |
| }; |
| const res = await fetch('/login', { |
| method: 'POST', |
| headers: { 'Content-Type': 'application/json' }, |
| body: JSON.stringify(data) |
| }); |
| const json = await res.json(); |
| if (res.ok && json.code === 0) { |
| localStorage.setItem('token', json.data); |
| window.location.href = 'home.html'; |
| } else { |
| alert(json.msg || json.error); |
| } |
| }); |
| </script> |
| </body> |
| </html> |