diff options
author | curly <curly@infernal.garden> | 2024-07-17 16:49:02 -0600 |
---|---|---|
committer | curly <curly@infernal.garden> | 2024-07-17 16:49:02 -0600 |
commit | 38bbeda4d654769a0d3c6d3a3a35851f1dc2c8ac (patch) | |
tree | 9ba175bbc0fcd44b84fdec13762cadd22c0e20c3 /src/main.js | |
parent | 1b239cf6a10fda1b3dc5b1a2f4009219470d5e5d (diff) | |
download | poko_web-38bbeda4d654769a0d3c6d3a3a35851f1dc2c8ac.tar.gz poko_web-38bbeda4d654769a0d3c6d3a3a35851f1dc2c8ac.tar.bz2 poko_web-38bbeda4d654769a0d3c6d3a3a35851f1dc2c8ac.zip |
admin page, add keys
Diffstat (limited to 'src/main.js')
-rw-r--r-- | src/main.js | 66 |
1 files changed, 64 insertions, 2 deletions
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 += ` + <a href="/admin/"> + <center class="button navbutton">ADMIN</center> + </a> + ` + } + } +} + +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) } } |