blob: 72fc1b8dcda7937340458887604f3b85563aee90 [file] [log] [blame]
Your Name695f6a62025-05-17 00:58:04 +08001<!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 Name292c25d2025-05-25 01:21:44 +080010 <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 Name695f6a62025-05-17 00:58:04 +080031 <button type="submit">注册</button>
32</form>
Your Name292c25d2025-05-25 01:21:44 +080033
Your Name695f6a62025-05-17 00:58:04 +080034<script>
Your Name292c25d2025-05-25 01:21:44 +080035 // 发送注册验证码
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 Name695f6a62025-05-17 00:58:04 +080043 });
Your Name292c25d2025-05-25 01:21:44 +080044 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 Name695f6a62025-05-17 00:58:04 +080062 });
Your Name292c25d2025-05-25 01:21:44 +080063 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 Name695f6a62025-05-17 00:58:04 +080069</script>
70</body>
71</html>