添加了swagger接口、重置密码、修改了usercontroller
Change-Id: Ib651fa9b0fe0b220eb8cb88dde2b63d6bf54895e
diff --git a/src/main/resources/static/register.html b/src/main/resources/static/register.html
index 549c790..72fc1b8 100644
--- a/src/main/resources/static/register.html
+++ b/src/main/resources/static/register.html
@@ -1,4 +1,3 @@
-<!-- src/main/resources/static/register.html -->
<!DOCTYPE html>
<html lang="zh-CN">
<head>
@@ -8,44 +7,65 @@
<body>
<h2>用户注册</h2>
<form id="regForm">
- <label>用户名:</label>
- <input type="text" name="username" required>
- <label>邮箱:</label>
- <input type="email" name="email" required>
- <button type="button" id="sendCode">发送验证码</button>
- <label>邮箱验证码:</label>
- <input type="text" name="verificationCode" required>
- <label>密码:</label>
- <input type="password" name="password" required>
- <label>身份证号(8 位数字):</label>
- <input type="number" name="identificationNumber" required>
+ <div>
+ <label>用户名:</label>
+ <input type="text" name="username" required>
+ </div>
+ <div>
+ <label>邮箱:</label>
+ <input type="email" name="email" required>
+ <button type="button" id="sendCode">发送验证码</button>
+ </div>
+ <div>
+ <label>邮箱验证码:</label>
+ <input type="text" name="verificationCode" required>
+ </div>
+ <div>
+ <label>密码:</label>
+ <input type="password" name="password" required>
+ </div>
+ <div>
+ <label>身份证号(8 位):</label>
+ <input type="text" name="identificationNumber" required pattern="\d{8}" maxlength="8">
+ </div>
<button type="submit">注册</button>
</form>
+
<script>
- document.getElementById('sendCode')
- .addEventListener('click', async () => {
- const form = new URLSearchParams();
- form.set('email', document.querySelector('[name=email]').value);
- const res = await fetch('/sendVerification', {
- method: 'POST',
- body: form
- });
- alert((await res.json()).msg);
+ // 发送注册验证码
+ document.getElementById('sendCode').addEventListener('click', async () => {
+ const email = document.querySelector('[name=email]').value;
+ if (!email) { alert('请先输入邮箱'); return; }
+ const res = await fetch('/sendVerification', {
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json' },
+ body: JSON.stringify({ email })
});
- document.getElementById('regForm')
- .addEventListener('submit', async e => {
- e.preventDefault();
- const form = new URLSearchParams(new FormData(e.target));
- const res = await fetch('/register', {
- method: 'POST',
- body: form
- });
- const json = await res.json();
- alert(json.msg);
- if (res.ok && json.code===0) {
- window.location.href='login.html';
- }
+ const json = await res.json();
+ alert(json.msg || json.error);
+ });
+
+ // 提交注册
+ document.getElementById('regForm').addEventListener('submit', async e => {
+ e.preventDefault();
+ const data = {
+ username: e.target.username.value,
+ email: e.target.email.value,
+ verificationCode: e.target.verificationCode.value,
+ password: e.target.password.value,
+ identificationNumber: e.target.identificationNumber.value
+ };
+ const res = await fetch('/register', {
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json' },
+ body: JSON.stringify(data)
});
+ const json = await res.json();
+ alert(json.msg || json.error);
+ if (res.ok && json.code === 0) {
+ window.location.href = 'login.html';
+ }
+ });
</script>
</body>
</html>