Add Temporary Admin Panel
This commit is contained in:
parent
a964f4d458
commit
fe262d895d
3 changed files with 81 additions and 1 deletions
|
|
@ -69,6 +69,17 @@
|
|||
<p style="text-align: center;">This does not remove your account from your devices. You will need to manually remove the files with FTPiiU or by removing the files from your Cemu MLC folder. If you are not sure how to do this, <a href="https://discord.gg/grMSxZf" target="_blank">ask in the discord.</a></p>
|
||||
</div>
|
||||
|
||||
<form id="ban" class="ban-form" style="display: none;">
|
||||
<h2>Admin Panel</h2>
|
||||
<p>VERY temporary</p>
|
||||
|
||||
<label for="ban-sfid">SFID to Ban:</label>
|
||||
<input type="text" id="ban-sfid"></input>
|
||||
<button type="submit">Ban Player</button>
|
||||
|
||||
<p id="ban-status" />
|
||||
</form>
|
||||
|
||||
<script type="text/javascript" src="/js/accounts.js"></script>
|
||||
</main>
|
||||
|
||||
|
|
|
|||
|
|
@ -446,6 +446,20 @@ code {
|
|||
}
|
||||
}
|
||||
|
||||
.ban-form {
|
||||
margin-top: 16px;
|
||||
}
|
||||
|
||||
.ban-form h2 {
|
||||
margin: 0;
|
||||
padding: 0px;
|
||||
}
|
||||
|
||||
.ban-form p {
|
||||
margin: 0;
|
||||
padding: 0px;
|
||||
}
|
||||
|
||||
.active {
|
||||
background-color: #a00b0b;
|
||||
border-color: #6d0606;
|
||||
|
|
|
|||
|
|
@ -32,6 +32,10 @@ function updateUserDataDisplay(data) {
|
|||
|
||||
document.getElementById("access-level").textContent = level[0];
|
||||
document.getElementById("access-level").style = `color: ${level[1]}; background-color: ${level[2]}; border-color: ${level[3]}`;
|
||||
|
||||
if (data["account_level"] >= 2) {
|
||||
document.getElementById("ban").style = ""
|
||||
}
|
||||
}
|
||||
|
||||
function logOut() {
|
||||
|
|
@ -112,4 +116,55 @@ async function deleteAccount() {
|
|||
|
||||
document.getElementById("confirm-delete").style = "display: none;"
|
||||
document.getElementById("delete-success").style = ""
|
||||
}
|
||||
}
|
||||
|
||||
// ADMIN PANEL - WILL BE REMOVED ONCE ACTUAL ADMIN PANEL IS FINISHED
|
||||
|
||||
document.getElementById("ban").addEventListener("submit", async function (event) {
|
||||
event.preventDefault();
|
||||
|
||||
const sfid = document.getElementById("ban-sfid").value;
|
||||
|
||||
let token;
|
||||
|
||||
let expiryStr = sessionStorage.getItem("authExpires");
|
||||
if (expiryStr) { // Expiry exists so token should exist
|
||||
token = sessionStorage.getItem("authToken");
|
||||
|
||||
let expiry = new Date(expiryStr);
|
||||
if (expiry < new Date()) { // Expired token
|
||||
window.location.href = "/account/login?redirect=/account"
|
||||
} else if (!token) { // Expiry Saved but No Token (shouldn't be possible but it'll be caught if it happens)
|
||||
window.location.href = "/account/login?redirect=/account"
|
||||
}
|
||||
} else { // Token Never Saved in Session
|
||||
window.location.href = "/account/login?redirect=/account"
|
||||
}
|
||||
|
||||
const response = await fetch("https://account.spfn.net/api/v2/admin/ban", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Authorization": `Bearer ${token}`,
|
||||
"Content-Type": "application/x-www-form-urlencoded"
|
||||
},
|
||||
body: `username=${sfid}`
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
let status = response.status;
|
||||
|
||||
if (status == 403) {
|
||||
document.getElementById("ban-status").innerText = "You are not a moderator."
|
||||
} else if (status == 400) {
|
||||
document.getElementById("ban-status").innerText = "Invalid Access Token. Refresh and log in again."
|
||||
} else if (status == 500) {
|
||||
document.getElementById("ban-status").innerText = "Server returned error whilst updating database."
|
||||
} else {
|
||||
document.getElementById("ban-status").innerText = `Server returned error: ${status}`
|
||||
}
|
||||
|
||||
throw new Error(`Error while banning player: ${status}`)
|
||||
}
|
||||
|
||||
document.getElementById("ban-status").innerText = `Successfully banned ${sfid}! Don't forget to report the ban in the Spacebar discord`
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in a new issue