From 7db5a5a274ae80d39e3cd933181ea873d0b50d8b Mon Sep 17 00:00:00 2001 From: whes1015 Date: Tue, 30 Jan 2024 03:36:17 +0800 Subject: [PATCH] fix: change password --- src/scripts/change.js | 75 ++++--------------------------------------- 1 file changed, 7 insertions(+), 68 deletions(-) diff --git a/src/scripts/change.js b/src/scripts/change.js index 90c408c..2251837 100644 --- a/src/scripts/change.js +++ b/src/scripts/change.js @@ -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"); @@ -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 ( @@ -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) => { @@ -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( "找不到此帳戶,可能尚未註冊。",