From cd3c8dd4f812f46b4f3116e7a2cba86279ed1017 Mon Sep 17 00:00:00 2001 From: Dominic Zimmer Date: Sat, 18 Jul 2020 01:14:14 +0200 Subject: [PATCH] Add adduser to admin view --- model.py | 2 ++ static/js/admin.js | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/model.py b/model.py index b1ba4ee..97584ee 100644 --- a/model.py +++ b/model.py @@ -101,6 +101,8 @@ class Model(object): @ApiMethod async def add_user(self, authtoken, username): + if username == "": + raise Exception("Username can't be blank!") self.verify_admin(authtoken) newuser = User(username = username) self.users[newuser.uuid] = newuser diff --git a/static/js/admin.js b/static/js/admin.js index 7e06117..200e797 100644 --- a/static/js/admin.js +++ b/static/js/admin.js @@ -27,6 +27,25 @@ Object.defineProperty(String.prototype, 'hashCode', { function render_table(data) { const users = Object.values(data.users); + const newusername = document.querySelector("#newusername"); + const newuserbutton = document.querySelector("#newuserbutton"); + + newuserbutton.addEventListener("click", async () => { + const r = await fetch(admin_api_path + 'add_user', { + method: "POST", + body: JSON.stringify({ + username: newusername.value, + }), + }); + + if (r.status !== 200) { + console.log("something went wrong"); + return; + } + + update_table(); + }) + const tbody = document.querySelector("#scoreboard tbody"); while (tbody.children.length) {