DIDS-Coursework/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/js/checkUser.js

35 lines
879 B
JavaScript
Raw Normal View History

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 = "./";
}
}));
});