Files
Course/Server/tests/test5/public/update.html

82 lines
2.2 KiB
HTML

<!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>