You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.8 KiB
48 lines
1.8 KiB
8 months ago
|
document.getElementById('changePasswd').addEventListener('click',function () {
|
||
|
changePasswd();
|
||
|
});
|
||
|
|
||
|
function changePasswd(){
|
||
|
const el_oldpasswd = document.getElementById('source_passwd');
|
||
|
const el_new_passwd = document.getElementById('new_passwd');
|
||
|
const el_again_passwd = document.getElementById('again_passwd');
|
||
|
const btn = document.getElementById('changePasswd');
|
||
|
oldpasswd = el_oldpasswd.value;
|
||
|
newpasswd = el_new_passwd.value;
|
||
|
againpasswd = el_again_passwd.value;
|
||
|
if(oldpasswd === "" || newpasswd === "" || againpasswd === ""){
|
||
|
alert("密码不能为空!")
|
||
|
}else{
|
||
|
if(newpasswd !== againpasswd){
|
||
|
alert("两次输入的密码不相同!")
|
||
|
}else{
|
||
|
btn.disabled = true;
|
||
|
//提交请求
|
||
|
const url = "/api/user/passwd"
|
||
|
const data = {"oldpasswd":oldpasswd,"newpasswd":newpasswd};
|
||
|
fetch(url, {
|
||
|
method: 'POST', // 指定请求方法为 POST
|
||
|
headers: {
|
||
|
'Content-Type': 'application/json' // 设置请求头,告诉服务器请求体的数据类型为 JSON
|
||
|
},
|
||
|
body: JSON.stringify(data) // 将 JavaScript 对象转换为 JSON 字符串
|
||
|
})
|
||
|
.then(response => response.json()) // 将响应解析为 JSON
|
||
|
.then(data => {
|
||
|
btn.disabled = false;
|
||
|
const istatus = data.status;
|
||
|
alert(data.msg);
|
||
|
if(istatus == 1){
|
||
|
el_oldpasswd.value = "";
|
||
|
el_new_passwd.value = "";
|
||
|
el_again_passwd.value = "";
|
||
|
}
|
||
|
})
|
||
|
.catch((error) => {
|
||
|
btn.disabled = false;
|
||
|
alert(`Error: ${error.message}`);
|
||
|
return;
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
}
|