diff options
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) } } |