blob: 7a87ccf0ae97089dc1a8d7157e72ee135b14791c [file] [log] [blame]
Your Name292c25d2025-05-25 01:21:44 +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="resetForm">
10 <div>
11 <label>邮箱:</label>
12 <input type="email" name="email" required>
13 <button type="button" id="sendResetCode">获取重置验证码</button>
14 </div>
15 <div>
16 <label>验证码:</label>
17 <input type="text" name="code" required>
18 </div>
19 <div>
20 <label>新密码:</label>
21 <input type="password" name="newPassword" required>
22 </div>
23 <button type="submit">重置密码</button>
24</form>
25
26<script>
27 // 发送重置验证码
28 document.getElementById('sendResetCode').addEventListener('click', async () => {
29 const email = document.querySelector('[name=email]').value;
30 if (!email) { alert('请先输入邮箱'); return; }
31 const res = await fetch('/sendResetCode', {
32 method: 'POST',
33 headers: { 'Content-Type': 'application/json' },
34 body: JSON.stringify({ email })
35 });
36 const json = await res.json();
37 alert(json.msg || json.error);
38 });
39
40 // 提交重置请求
41 document.getElementById('resetForm').addEventListener('submit', async e => {
42 e.preventDefault();
43 const data = {
44 email: e.target.email.value,
45 code: e.target.code.value,
46 newPassword: e.target.newPassword.value
47 };
48 const res = await fetch('/resetPassword', {
49 method: 'POST',
50 headers: { 'Content-Type': 'application/json' },
51 body: JSON.stringify(data)
52 });
53 const json = await res.json();
54 alert(json.msg || json.error);
55 if (res.ok && json.code === 0) {
56 window.location.href = 'login.html';
57 }
58 });
59</script>
60</body>
61</html>