Make session control fully ajax
This commit is contained in:
@@ -16,6 +16,44 @@ body {
|
||||
font-family: "WDXL Lubrifont JP N", sans-serif;
|
||||
}
|
||||
|
||||
#message {
|
||||
color: white;
|
||||
position: absolute;
|
||||
background-color: #1b262c;
|
||||
width: calc(100vw - 10px);
|
||||
padding: 5px;
|
||||
display: block;
|
||||
text-align: center;
|
||||
font-size: 21px;
|
||||
font-family: "WDXL Lubrifont JP N", sans-serif;
|
||||
opacity: 1;
|
||||
transition: opacity 0.5s ease-in-out;
|
||||
}
|
||||
|
||||
#message.hide {
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
#message::after {
|
||||
content: "X";
|
||||
color: white;
|
||||
position: absolute;
|
||||
right: 10px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
#message:hover::after {
|
||||
color: #90bdd9;
|
||||
}
|
||||
|
||||
#message:empty {
|
||||
display: none;
|
||||
}
|
||||
|
||||
#message:empty:after {
|
||||
display: none;
|
||||
}
|
||||
|
||||
button {
|
||||
font-family: "WDXL Lubrifont JP N", sans-serif;
|
||||
font-size: 18px;
|
||||
@@ -132,7 +170,7 @@ input {
|
||||
}
|
||||
|
||||
.form button {
|
||||
margin-top: 20px;
|
||||
margin-top: 10px;
|
||||
padding: 10px;
|
||||
background-color: #3498db;
|
||||
color: white;
|
||||
@@ -152,6 +190,9 @@ input {
|
||||
|
||||
.header-right {
|
||||
margin-right: 20px;
|
||||
display: flex;
|
||||
white-space: nowrap;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.account-button {
|
||||
@@ -160,7 +201,6 @@ input {
|
||||
cursor: pointer;
|
||||
color: #90bdd9;
|
||||
font-size: 23px;
|
||||
margin-right: 10px;
|
||||
font-family: "WDXL Lubrifont JP N", sans-serif;
|
||||
}
|
||||
|
||||
|
@@ -21,6 +21,9 @@ window.onload = async () => {
|
||||
const forgotButton = document.getElementById("forgot-link");
|
||||
const closeButton = document.getElementById("close");
|
||||
|
||||
const message = document.getElementById("message");
|
||||
message.onclick = () => message.classList.add("hide");
|
||||
|
||||
const signedInMeta = document.querySelector('meta[name="signed_in"]');
|
||||
const isSignedIn = signedInMeta?.content === "true";
|
||||
if (isSignedIn) {
|
||||
@@ -49,14 +52,20 @@ window.onload = async () => {
|
||||
|
||||
loginButton?.addEventListener("click", () => showPopup(loginSection));
|
||||
signupButton?.addEventListener("click", () => showPopup(signupSection));
|
||||
logoutButton?.addEventListener(
|
||||
"click",
|
||||
() => (window.location.href = "/logout"),
|
||||
);
|
||||
logoutButton?.addEventListener("click", async () => {
|
||||
const res = await fetch("/logout", { method: "POST" });
|
||||
const data = await res.json();
|
||||
message.innerText = data.message;
|
||||
message.classList.remove("hide");
|
||||
if (data.success == "true") {
|
||||
loginButton.style.display = "block";
|
||||
signupButton.style.display = "block";
|
||||
logoutButton.style.display = "none";
|
||||
}
|
||||
});
|
||||
forgotButton?.addEventListener("click", () => showPopup(forgotPassSection));
|
||||
closeButton?.addEventListener("click", hidePopup);
|
||||
|
||||
// TODO: if succesful hide form and popup success message
|
||||
loginForm?.addEventListener("submit", async (e) => {
|
||||
e.preventDefault();
|
||||
const { username, pass } = loginForm;
|
||||
@@ -71,10 +80,12 @@ window.onload = async () => {
|
||||
loginButton.style.display = "none";
|
||||
signupButton.style.display = "none";
|
||||
logoutButton.style.display = "block";
|
||||
message.innerText = data.message;
|
||||
message.classList.remove("hide");
|
||||
hidePopup();
|
||||
}
|
||||
});
|
||||
|
||||
// TODO: if succesful hide form and popup success message
|
||||
signupForm?.addEventListener("submit", async (e) => {
|
||||
e.preventDefault();
|
||||
const { username, email, pass } = signupForm;
|
||||
@@ -93,6 +104,9 @@ window.onload = async () => {
|
||||
loginButton.style.display = "none";
|
||||
signupButton.style.display = "none";
|
||||
logoutButton.style.display = "block";
|
||||
message.innerText = data.message;
|
||||
message.classList.remove("hide");
|
||||
hidePopup();
|
||||
}
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user