2022-11-24 09:15:38 +00:00
|
|
|
// Login stuff
|
|
|
|
|
2022-12-15 14:50:58 +00:00
|
|
|
document.addEventListener("DOMContentLoaded", () =>
|
|
|
|
{
|
|
|
|
fetch("isLoggedIn.php").then(res => res.json().then(json =>
|
|
|
|
{
|
|
|
|
if (json.message === "ok")
|
|
|
|
{
|
|
|
|
window.location.href = "./search.html";
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
|
2022-11-24 09:15:38 +00:00
|
|
|
document.querySelector("#login").addEventListener("submit", e =>
|
|
|
|
{
|
|
|
|
e.preventDefault();
|
|
|
|
let formData = new FormData();
|
|
|
|
formData.append("username", document.querySelector("#username").value);
|
|
|
|
formData.append("password", document.querySelector("#password").value);
|
2022-11-29 15:48:18 +00:00
|
|
|
fetch("login.php", {
|
2022-11-24 09:15:38 +00:00
|
|
|
method: "POST",
|
|
|
|
body: formData
|
|
|
|
}).then(res => res.json().then(json =>
|
|
|
|
{
|
|
|
|
if (json.message === "ok")
|
|
|
|
{
|
|
|
|
window.location.href = "search.html";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-11-29 15:48:18 +00:00
|
|
|
alert(json.message);
|
2022-11-24 09:15:38 +00:00
|
|
|
}
|
|
|
|
}));
|
|
|
|
|
|
|
|
});
|