send request to the server

This commit is contained in:
2026-03-31 21:39:38 -04:00
parent d283ad0a0a
commit c628c688f7

View File

@@ -160,43 +160,66 @@
} }
changePasswordButton.addEventListener("click", () => { changePasswordButton.addEventListener("click", () => {
if (document.getElementById("current_password").value == "") { if (document.getElementById("current_password").value === "") {
displayError("Please enter current password"); displayError("Please enter current password");
return; return;
} }
if ( if (document.getElementById("new_password").value === "") {
document.getElementById("new_password").value !=
document.getElementById("new_password_repeat").value
) {
displayError("New password and new password repeat do not match");
return;
}
if (document.getElementById("new_password").value == "") {
document
.getElementById("password_error")
.classList.remove("hidden");
displayError("No value for new password"); displayError("No value for new password");
return; return;
} }
if (document.getElementById("new_password_repeat").value == "") { if (document.getElementById("new_password_repeat").value === "") {
displayError("Please repeat new password"); displayError("Please repeat new password");
return; return;
} }
if (
document.getElementById("new_password").value !==
document.getElementById("new_password_repeat").value
) {
displayError("New password and new password repeat do not match");
return;
}
const formData = new FormData(); const formData = new FormData();
formData.append( formData.append(
"csrf_token", "csrf_token",
document.getElementById("csrf_token_storage").value, document.getElementById("csrf_token_storage").value,
); );
formData.append("old_password", file); formData.append(
"old_password",
document.getElementById("current_password").value,
);
formData.append(
"new_password",
document.getElementById("new_password").value,
);
formData.append(
"new_password_repeat",
document.getElementById("new_password_repeat").value,
);
document fetch("/change-password", {
.getElementById("change_password_dialogue") method: "POST",
.classList.add("hidden"); body: formData,
document.getElementById("popup_background").classList.add("hidden"); })
.then((res) => res.json())
.then((data) => {
// handle success
})
.catch((err) => {
displayError("Something went wrong");
})
.then((data) => {
document
.getElementById("change_password_dialogue")
.classList.add("hidden");
document
.getElementById("popup_background")
.classList.add("hidden");
});
}); });
</script> </script>