From cb2ec083d6befe2c932d9fefd8bb6caa79d4a23b Mon Sep 17 00:00:00 2001 From: BloxerHD018 Date: Sat, 4 Jul 2026 21:09:05 +0100 Subject: [PATCH] Add Temporary Admin Panel --- static/account/index.html | 11 ++++++++ static/css/style.css | 14 ++++++++++ static/js/accounts.js | 57 ++++++++++++++++++++++++++++++++++++++- 3 files changed, 81 insertions(+), 1 deletion(-) diff --git a/static/account/index.html b/static/account/index.html index 060e1e7..3c0a810 100644 --- a/static/account/index.html +++ b/static/account/index.html @@ -69,6 +69,17 @@

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, ask in the discord.

+ + diff --git a/static/css/style.css b/static/css/style.css index d0b39dd..26ad923 100644 --- a/static/css/style.css +++ b/static/css/style.css @@ -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; diff --git a/static/js/accounts.js b/static/js/accounts.js index 8fced5a..eb8755a 100644 --- a/static/js/accounts.js +++ b/static/js/accounts.js @@ -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 = "" -} \ No newline at end of file +} + +// 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` +})