Make accounts frontend!

This commit is contained in:
2025-06-26 18:08:59 +03:00
parent 652b391d6f
commit 169c4faa7d
7 changed files with 285 additions and 64 deletions
+127 -38
View File
@@ -1,43 +1,132 @@
const login_form = document.getElementById("login-form");
const login_button = document.getElementById("login-button");
const signup_form = document.getElementById("signup-form");
const signup_button = document.getElementById("signup-button");
window.onload = async () => {
const login_form = document.getElementById("login-form");
const login_button = document.getElementById("login-button");
const signup_form = document.getElementById("signup-form");
const signup_button = document.getElementById("signup-button");
const logout_button = document.getElementById("logout-button");
const forgot_button = document.getElementById("forgot-button");
const forgot_form = document.getElementById("forgot-form");
login_button.onclick = () => {
document.getElementById("login").style.display = "block";
};
forgot_button.onclick = () => {
document.getElementById("popup").classList.add("active");
document.getElementById("forgot-pass").classList.add("active");
document.getElementById("login").classList.remove("active");
document.getElementById("signup").classList.remove("active");
document.getElementById("reset-pass").classList.remove("active");
};
signup_button.onclick = () => {
document.getElementById("signup").style.display = "block";
};
forgot_form.onsubmit = async (e) => {
e.preventDefault();
const email = forgot_form.email.value;
const res = await fetch("/forgot_password", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ email }),
});
const data = await res.json();
document.getElementById("forgot-info").innerHTML = data.message;
};
login_form.onsubmit = async (e) => {
e.preventDefault();
const username = login_form.username.value;
const pass = login_form.pass.value;
let response = await fetch("/login", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ username, pass }),
});
response = await response.json();
document.getElementById("login-info").innerText = response.message;
};
logout_button.onclick = () => {
window.location.href = "/logout";
};
signup_form.onsubmit = async (e) => {
e.preventDefault();
const username = signup_form.username.value;
const email = signup_form.email.value;
const pass = signup_form.pass.value;
let response = await fetch("/signup", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ username, email, pass }),
});
response = await response.json();
document.getElementById("signup-info").innerText = response.message;
login_button.onclick = () => {
document.getElementById("popup").classList.add("active");
document.getElementById("login").classList.add("active");
document.getElementById("signup").classList.remove("active");
document.getElementById("forgot-pass").classList.remove("active");
document.getElementById("reset-pass").classList.remove("active");
};
signup_button.onclick = () => {
document.getElementById("popup").classList.add("active");
document.getElementById("signup").classList.add("active");
document.getElementById("login").classList.remove("active");
document.getElementById("forgot-pass").classList.remove("active");
document.getElementById("reset-pass").classList.remove("active");
};
document.getElementById("close").onclick = () => {
document.getElementById("popup").classList.remove("active");
document.getElementById("login").classList.remove("active");
document.getElementById("signup").classList.remove("active");
document.getElementById("forgot-pass").classList.remove("active");
document.getElementById("reset-pass").classList.remove("active");
};
login_form.onsubmit = async (e) => {
e.preventDefault();
const username = login_form.username.value;
const pass = login_form.pass.value;
let response = await fetch("/login", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ username, pass }),
});
response = await response.json();
document.getElementById("login-info").innerText = response.message;
};
signup_form.onsubmit = async (e) => {
e.preventDefault();
const username = signup_form.username.value;
const email = signup_form.email.value;
const pass = signup_form.pass.value;
let response = await fetch("/signup", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ username, email, pass }),
});
response = await response.json();
document.getElementById("signup-info").innerText = response.message;
};
const params = new URLSearchParams(window.location.search);
const reset_code = params.get("reset_code");
if (reset_code) {
let response = await fetch("/pass_reset?", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ code: reset_code }),
});
let status = response.status;
if (status == 200) {
document.getElementById("popup").classList.add("active");
document.getElementById("reset-pass").classList.add("active");
document.getElementById("login").classList.remove("active");
document.getElementById("signup").classList.remove("active");
document.getElementById("forgot-pass").classList.remove("active");
document.getElementById("reset-form").onsubmit = async (e) => {
e.preventDefault();
const pass = document.getElementById("reset-form").pass.value;
const pass_confirm =
document.getElementById("reset-form").pass_confirm.value;
if (pass != pass_confirm) {
document.getElementById("reset-info").innerText =
"Passwords do not match";
return;
}
let response = await fetch("/reset_password/" + reset_code, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ pass }),
});
response = await response.json();
document.getElementById("reset-info").innerText = response.message;
};
} else {
window.location.href = "/";
}
}
};