| Your Name | 695f6a6 | 2025-05-17 00:58:04 +0800 | [diff] [blame] | 1 | <!DOCTYPE html> |
| 2 | <html lang="zh-CN"> |
| 3 | <head> |
| 4 | <meta charset="UTF-8"> |
| 5 | <title>注册</title> |
| 6 | </head> |
| 7 | <body> |
| 8 | <h2>用户注册</h2> |
| 9 | <form id="regForm"> |
| Your Name | 292c25d | 2025-05-25 01:21:44 +0800 | [diff] [blame] | 10 | <div> |
| 11 | <label>用户名:</label> |
| 12 | <input type="text" name="username" required> |
| 13 | </div> |
| 14 | <div> |
| 15 | <label>邮箱:</label> |
| 16 | <input type="email" name="email" required> |
| 17 | <button type="button" id="sendCode">发送验证码</button> |
| 18 | </div> |
| 19 | <div> |
| 20 | <label>邮箱验证码:</label> |
| 21 | <input type="text" name="verificationCode" required> |
| 22 | </div> |
| 23 | <div> |
| 24 | <label>密码:</label> |
| 25 | <input type="password" name="password" required> |
| 26 | </div> |
| 27 | <div> |
| 28 | <label>身份证号(8 位):</label> |
| 29 | <input type="text" name="identificationNumber" required pattern="\d{8}" maxlength="8"> |
| 30 | </div> |
| Your Name | 695f6a6 | 2025-05-17 00:58:04 +0800 | [diff] [blame] | 31 | <button type="submit">注册</button> |
| 32 | </form> |
| Your Name | 292c25d | 2025-05-25 01:21:44 +0800 | [diff] [blame] | 33 | |
| Your Name | 695f6a6 | 2025-05-17 00:58:04 +0800 | [diff] [blame] | 34 | <script> |
| Your Name | 292c25d | 2025-05-25 01:21:44 +0800 | [diff] [blame] | 35 | // 发送注册验证码 |
| 36 | document.getElementById('sendCode').addEventListener('click', async () => { |
| 37 | const email = document.querySelector('[name=email]').value; |
| 38 | if (!email) { alert('请先输入邮箱'); return; } |
| 39 | const res = await fetch('/sendVerification', { |
| 40 | method: 'POST', |
| 41 | headers: { 'Content-Type': 'application/json' }, |
| 42 | body: JSON.stringify({ email }) |
| Your Name | 695f6a6 | 2025-05-17 00:58:04 +0800 | [diff] [blame] | 43 | }); |
| Your Name | 292c25d | 2025-05-25 01:21:44 +0800 | [diff] [blame] | 44 | const json = await res.json(); |
| 45 | alert(json.msg || json.error); |
| 46 | }); |
| 47 | |
| 48 | // 提交注册 |
| 49 | document.getElementById('regForm').addEventListener('submit', async e => { |
| 50 | e.preventDefault(); |
| 51 | const data = { |
| 52 | username: e.target.username.value, |
| 53 | email: e.target.email.value, |
| 54 | verificationCode: e.target.verificationCode.value, |
| 55 | password: e.target.password.value, |
| 56 | identificationNumber: e.target.identificationNumber.value |
| 57 | }; |
| 58 | const res = await fetch('/register', { |
| 59 | method: 'POST', |
| 60 | headers: { 'Content-Type': 'application/json' }, |
| 61 | body: JSON.stringify(data) |
| Your Name | 695f6a6 | 2025-05-17 00:58:04 +0800 | [diff] [blame] | 62 | }); |
| Your Name | 292c25d | 2025-05-25 01:21:44 +0800 | [diff] [blame] | 63 | const json = await res.json(); |
| 64 | alert(json.msg || json.error); |
| 65 | if (res.ok && json.code === 0) { |
| 66 | window.location.href = 'login.html'; |
| 67 | } |
| 68 | }); |
| Your Name | 695f6a6 | 2025-05-17 00:58:04 +0800 | [diff] [blame] | 69 | </script> |
| 70 | </body> |
| 71 | </html> |