From 38bbeda4d654769a0d3c6d3a3a35851f1dc2c8ac Mon Sep 17 00:00:00 2001 From: curly Date: Wed, 17 Jul 2024 16:49:02 -0600 Subject: admin page, add keys --- src/admin/index.html | 31 +++++++++++++++++++++ src/admin/regkeys/index.html | 57 ++++++++++++++++++++++++++++++++++++++ src/main.js | 66 ++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 152 insertions(+), 2 deletions(-) create mode 100644 src/admin/index.html create mode 100644 src/admin/regkeys/index.html (limited to 'src') diff --git a/src/admin/index.html b/src/admin/index.html new file mode 100644 index 0000000..16e459f --- /dev/null +++ b/src/admin/index.html @@ -0,0 +1,31 @@ + + + + + + USER + + +
+ + + + + + +
+
+
+

ADMIN

+
+
+
+
+
+ + + \ No newline at end of file diff --git a/src/admin/regkeys/index.html b/src/admin/regkeys/index.html new file mode 100644 index 0000000..de6ecf1 --- /dev/null +++ b/src/admin/regkeys/index.html @@ -0,0 +1,57 @@ + + + + + + REGISTRATION KEYS + + +
+ + + + + + +
+
+
+

ADD KEY

+
+
+
+
+ + + +
+
+
+
+
+

DELETE KEY

+
+
+
+
+ + + +
+
+
+
+
+

KEY LIST

+
+
+
+
+
+ + + \ No newline at end of file diff --git a/src/main.js b/src/main.js index e6d9264..cd27d54 100644 --- a/src/main.js +++ b/src/main.js @@ -310,9 +310,37 @@ async function update_name_form() { } +async function is_admin() { + const session = get_session(); + const id = get_id(); + + if (session != "") { + if (id != "") { + const url = server + "/user/get" + const body = {"id": id, "session": session} + const req = await xhttp_post(url, body); + + if (req.status == 200) { + if (req.body.is_admin == true) { + return true + } + } else if (req.status == 404) { + if (req.body == "Not Authenticated") { + del_session() + return false + } + } + } else { + del_session() + } + } + + return false +} + window.onload = async function() { - // if not on a user page - if (window.location.pathname.indexOf("/user") == -1) { + // if not on a user page and not an admin page + if (window.location.pathname.indexOf("/user") == -1 && window.location.pathname.indexOf("/admin") == -1) { // and if logged in if (await is_logged_in()) { // move to the user index page @@ -320,6 +348,40 @@ window.onload = async function() { } } else if (window.location.pathname == "/user/") { await user() + } else if (window.location.pathname == "/admin/regkeys/") { + await regkeys() + } + + if (await is_admin()) { + const elements = document.getElementsByTagName("header"); + for (x in elements) { + elements[x].innerHTML += ` + + + + ` + } + } +} + +async function regkeys() { + const list = document.getElementById("keylist"); + list.innerHTML = "NOT IMPLEMENTED" +} + +async function add_regkey_form() { + const id = get_id(); + const session = get_session(); + const key = document.getElementById("key_add").value; + + const url = server + "/admin/regkey/new" + const body = {"id": id, "session": session, "key": key} + const req = await xhttp_post(url, body); + + if (req.status == 200) { + window.location.href = window.location.href + } else { + alert(req.status + ": " + req.body) } } -- cgit v1.2.3