35 lines
879 B
JavaScript
35 lines
879 B
JavaScript
document.addEventListener("DOMContentLoaded", () =>
|
|
{
|
|
fetch("isLoggedIn.php").then(res => res.json().then(json =>
|
|
{
|
|
if (json.message !== "ok")
|
|
{
|
|
window.location.href = "./";
|
|
}
|
|
else
|
|
{
|
|
document.querySelector("#title h1").innerText = "Logged in as: " + json.username;
|
|
let adminLinks = document.querySelectorAll(".admin");
|
|
for (let adminLink of adminLinks)
|
|
{
|
|
if (json.admin === true)
|
|
{
|
|
adminLink.style.display = "block";
|
|
}
|
|
}
|
|
|
|
}
|
|
}));
|
|
});
|
|
|
|
document.querySelector("#logout").addEventListener("click", e =>
|
|
{
|
|
e.preventDefault();
|
|
fetch("logout.php").then(res => res.json().then(json =>
|
|
{
|
|
if (json.message === "ok")
|
|
{
|
|
window.location.href = "./";
|
|
}
|
|
}));
|
|
}); |