feat(server.tests.test5): 新增 server 实验5
This commit is contained in:
77
Server/tests/test5/public/login.html
Normal file
77
Server/tests/test5/public/login.html
Normal file
@@ -0,0 +1,77 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<style>
|
||||
body,
|
||||
html {
|
||||
margin: 0;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
form {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: 280px;
|
||||
gap: 12px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
input {
|
||||
padding: 8px;
|
||||
font-size: 15px;
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
button {
|
||||
padding: 10px;
|
||||
font-size: 16px;
|
||||
cursor: pointer;
|
||||
}
|
||||
</style>
|
||||
<title>Login</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<form id="loginForm">
|
||||
<input type="text" id="username" placeholder="请输入用户名">
|
||||
<input type="password" id="password" placeholder="请输入密码">
|
||||
<button type="button" id="loginBtn">登录</button>
|
||||
</form>
|
||||
|
||||
<script>
|
||||
document.getElementById("loginBtn").addEventListener("click", login);
|
||||
|
||||
async function login() {
|
||||
const username = document.getElementById("username").value.trim();
|
||||
const password = document.getElementById("password").value.trim();
|
||||
|
||||
if (!username || !password) {
|
||||
alert("请输入用户名和密码");
|
||||
return;
|
||||
}
|
||||
|
||||
const res = await fetch("http://localhost:3000/login", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
body: JSON.stringify({ username, password })
|
||||
});
|
||||
|
||||
const data = await res.text();
|
||||
alert(data);
|
||||
}
|
||||
</script>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
106
Server/tests/test5/public/register.html
Normal file
106
Server/tests/test5/public/register.html
Normal file
@@ -0,0 +1,106 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Register</title>
|
||||
<style>
|
||||
body,
|
||||
html {
|
||||
margin: 0;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
form {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: 280px;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
input,
|
||||
select,
|
||||
textarea {
|
||||
padding: 8px;
|
||||
font-size: 15px;
|
||||
}
|
||||
|
||||
button {
|
||||
padding: 10px;
|
||||
font-size: 16px;
|
||||
cursor: pointer;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<form id="registerForm">
|
||||
<input id="username" type="text" placeholder="用户名" required>
|
||||
<input id="password" type="password" placeholder="密码" required>
|
||||
<input id="email" type="email" placeholder="邮箱" required>
|
||||
|
||||
<select id="gender">
|
||||
<option value="male">男</option>
|
||||
<option value="female">女</option>
|
||||
</select>
|
||||
|
||||
<input id="hobbies" type="text" placeholder="爱好(用逗号分隔,例如:听音乐,玩游戏)">
|
||||
|
||||
<input id="city" type="text" placeholder="城市,例如:重庆">
|
||||
|
||||
<textarea id="description" rows="3" placeholder="自我介绍"></textarea>
|
||||
|
||||
<button type="button" id="registerBtn">注册</button>
|
||||
</form>
|
||||
|
||||
<script>
|
||||
document.getElementById("registerBtn").addEventListener("click", register);
|
||||
|
||||
async function register() {
|
||||
const username = document.getElementById("username").value.trim();
|
||||
const password = document.getElementById("password").value.trim();
|
||||
const email = document.getElementById("email").value.trim();
|
||||
const gender = document.getElementById("gender").value;
|
||||
const hobbiesInput = document.getElementById("hobbies").value.trim();
|
||||
const city = document.getElementById("city").value.trim();
|
||||
const description = document.getElementById("description").value.trim();
|
||||
|
||||
if (!username || !password || !email) {
|
||||
alert("请填写必填字段:用户名、密码、邮箱");
|
||||
return;
|
||||
}
|
||||
|
||||
const hobbies = hobbiesInput ? hobbiesInput.split(",").map(i => i.trim()) : [];
|
||||
|
||||
const payload = {
|
||||
username,
|
||||
password,
|
||||
email,
|
||||
gender,
|
||||
hobbies,
|
||||
city,
|
||||
description
|
||||
};
|
||||
|
||||
const res = await fetch("http://localhost:3000/register", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
body: JSON.stringify(payload)
|
||||
});
|
||||
|
||||
const data = await res.text(); // 后端是字符串
|
||||
alert(data);
|
||||
}
|
||||
</script>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
82
Server/tests/test5/public/update.html
Normal file
82
Server/tests/test5/public/update.html
Normal file
@@ -0,0 +1,82 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Change Password</title>
|
||||
<style>
|
||||
body,
|
||||
html {
|
||||
margin: 0;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
form {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: 280px;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
input {
|
||||
padding: 8px;
|
||||
font-size: 15px;
|
||||
}
|
||||
|
||||
button {
|
||||
padding: 10px;
|
||||
font-size: 16px;
|
||||
cursor: pointer;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<form id="changePwdForm">
|
||||
<input id="username" type="text" placeholder="用户名" required>
|
||||
<input id="currentPassword" type="password" placeholder="当前密码" required>
|
||||
<input id="newPassword" type="password" placeholder="新密码" required>
|
||||
<button type="button" id="changePwdBtn">修改密码</button>
|
||||
</form>
|
||||
|
||||
<script>
|
||||
document.getElementById("changePwdBtn").addEventListener("click", changePassword);
|
||||
|
||||
async function changePassword() {
|
||||
const username = document.getElementById("username").value.trim();
|
||||
const currentPassword = document.getElementById("currentPassword").value.trim();
|
||||
const newPassword = document.getElementById("newPassword").value.trim();
|
||||
|
||||
if (!username || !currentPassword || !newPassword) {
|
||||
alert("请填写所有字段");
|
||||
return;
|
||||
}
|
||||
|
||||
const payload = {
|
||||
username,
|
||||
currentPassword,
|
||||
newPassword
|
||||
};
|
||||
|
||||
const res = await fetch("http://localhost:3000/update-password", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
body: JSON.stringify(payload)
|
||||
});
|
||||
|
||||
const data = await res.text(); // 返回字符串
|
||||
alert(data);
|
||||
}
|
||||
</script>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user