-
Notifications
You must be signed in to change notification settings - Fork 2
/
reset-password.js
38 lines (35 loc) · 1.15 KB
/
reset-password.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
document.getElementById("reset-password-form").addEventListener("submit", (e) => {
e.preventDefault();
const password = document.getElementById("password").value;
const confirmPassword = document.getElementById("confirm-password").value;
if (password !== confirmPassword) {
alert("Passwords do not match.");
return;
}
const token = new URLSearchParams(window.location.search).get("token");
fetch("https://play.retro-mmo.com/reset-password", {
body: JSON.stringify({
password,
token
}),
headers: {
"Content-Type": "application/json"
},
method: "POST"
}).then(({ status }) => {
if (String(status).startsWith("5")) {
alert("The request could not be completed");
}
else {
switch (status) {
case 200:
alert("Your password has been reset!");
break;
case 401:
alert("Your password reset link is invalid or has expired.");
break;
}
}
location.replace("./");
});
});