Skip to content

Commit

Permalink
fix: change password
Browse files Browse the repository at this point in the history
  • Loading branch information
whes1015 committed Jan 29, 2024
1 parent f0a2219 commit 7db5a5a
Showing 1 changed file with 7 additions and 68 deletions.
75 changes: 7 additions & 68 deletions src/scripts/change.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const password_strength = document.getElementById("password-strength");
const new_password = document.getElementById("new-password");
const email = document.getElementById("email");
const password = document.getElementById("password");
const repeat_password = document.getElementById("repeat-password");
const success_view = document.getElementById("success-view");
const form_view = document.getElementById("form-view");
const container = document.getElementById("container");
Expand All @@ -16,7 +15,7 @@ new_password.oninput = (e) => {
this.value = new_password.value;
password_strength.style.display = "block";

if (this.value.match(/(?=.*[^A-Za-z0-9@_\.-])/))
if (this.value.match(/(?=.*[^A-Za-z0-9@_.-])/))
return (password_strength.className = "error invalid");

if (
Expand All @@ -40,51 +39,21 @@ if (!params.token)
document.location.replace("./login.html");

changeForm.addEventListener("submit", (e) => {

container.style.height = form_view.offsetHeight + 76;
form_view.style.position = "absolute";
success_view.style.position = "absolute";
success_view.style.display = "block";
form_view.style.opacity = 0;
container.style.height = success_view.offsetHeight + 76;
setTimeout(() => {
success_view.style.position = "";
success_view.style.opacity = 1;
form_view.style.display = "none";
form_view.style.position = "";
}, 100);

setTimeout(() => (window.location.href = "./login.html"), 5_000);

e.preventDefault();

email.setCustomValidity("");
password.setCustomValidity("");
repeat_password.setCustomValidity("");
new_password.setCustomValidity("");

let values = {
email : email.value,
pass : password.value,
new_pass : new_password.value,
};

if (params.token)
values = {
token : params.token,
new_pass : new_password.value,
};


submit.disabled = true;

console.log("test");

fetch("https://api.exptech.com.tw/api/v1/et/change", {
method : "POST",
headers : { "Content-Type": "application/json" },
body : JSON.stringify({
token : values.token,
email : values.email,
pass : values.pass,
new_pass : values.new_pass,
token : params.token,
new_pass : new_password.value,
}),
})
.then(async (res) => {
Expand All @@ -105,48 +74,18 @@ changeForm.addEventListener("submit", (e) => {
setTimeout(() => (window.location.href = "./login.html"), 5_000);
} else {
switch (await res.text()) {
case "Invaild email!": {
email.setCustomValidity("電子郵件地址無效。");
email.reportValidity();
break;
}

case "Invaild pass!": {
password.setCustomValidity("舊密碼無效。");
password.reportValidity();
break;
}

case "Invaild new pass!": {
new_password.setCustomValidity("新密碼無效。");
new_password.reportValidity();
break;
}

case "Pass format error!": {
password.setCustomValidity("舊密碼格式錯誤。");
password.reportValidity();
break;
}

case "New pass format error!": {
new_password.setCustomValidity("新密碼格式錯誤。");
new_password.reportValidity();
break;
}

case "No changes found!": {
new_password.setCustomValidity("沒有發現任何變化。");
new_password.reportValidity();
break;
}

case "Pass error!": {
password.setCustomValidity("舊密碼錯誤。");
password.reportValidity();
break;
}

case "This account was not found!": {
new_password.setCustomValidity(
"找不到此帳戶,可能尚未註冊。",
Expand Down

0 comments on commit 7db5a5a

Please sign in to comment.