const login = document.querySelector("#login"); const logout = document.querySelector("#logout"); const stdModal = document.querySelector("#stdModal"); if (logout) { logout.addEventListener("click", () => { fetch("director.php", { method: "POST", headers: { "Content-Type": "application/x-www-form-urlencoded", }, body: "ajaxId=logout", }).then(() => { if ("startViewTransition" in document) { document.startViewTransition(() => { window.location.href = "spaces.php?view=list"; }); } else { window.location.href = "spaces.php?view=list"; } }); }); } if (login) { login.addEventListener("click", () => { console.log("click"); stdModal.innerHTML = `

Log In

`; stdModal.style.display = "flex"; const form = document.querySelector("#login_form"); const username_field = form.querySelector("#username"); const passwordField = form.querySelector("#password"); const submit_button = form.querySelector('input[type="submit"]'); submit_button.addEventListener("click", async (e) => { e.preventDefault(); requestAuth(username_field.value, passwordField.value); }); function requestAuth(username, password) { fetch("director.php", { method: "POST", headers: { "Content-Type": "application/x-www-form-urlencoded", }, body: "ajaxId=login&username=" + username + "&password=" + password, }) .then((response) => { if (!response.ok) { console.log("Login Failed!"); } return response.json(); }) .then((data) => { console.log(data); if ("startViewTransition" in document) { document.startViewTransition(() => { window.location.href = data["redirect"]; }); } else { // Fallback for browsers that don't support View Transitions window.location.href = data["redirect"]; } }); } }); }