- |
+
+
+ |
|
|
diff --git a/model.py b/model.py
index 97584ee..7becbf9 100644
--- a/model.py
+++ b/model.py
@@ -33,7 +33,7 @@ class Model(object):
model["users"] = {}
#print(f"loaded model: {model}")
self.users = { uuid : User(model=model["users"][uuid]) for uuid in model["users"]}
-
+
#for _ in range(5):
# newuser = User()
# self.users[newuser.uuid] = newuser
@@ -41,16 +41,16 @@ class Model(object):
self.secretlookup = { self.users[uuid].get_secret() : uuid for uuid in self.users }
print(f'Admin Token: {hashlib.sha256(SECRET.encode() + b"admintoken").hexdigest()}')
- for user in self.users.values():
- print(f"{user.name.rjust(25)} -> /dealer/{user.get_secret()}")
+ #for user in self.users.values():
+ # print(f"{user.name.rjust(25)} -> /dealer/{user.get_secret()}")
+
-
def to_json(self):
model = {
"users": { uuid: self.users[uuid].to_json() for uuid in self.users },
}
- print(model)
+ #print(model)
return model
def verify_user(self, authtoken):
@@ -99,11 +99,19 @@ class Model(object):
# Admin API Methods
#
+ @ApiMethod
+ async def get_secret(self, authtoken, uuid):
+ self.verify_admin(authtoken)
+ if uuid not in self.users:
+ raise Exception("Incorrect UUID")
+ user = self.users[uuid]
+ return {uuid: self.users[uuid].get_secret()}
+
@ApiMethod
async def add_user(self, authtoken, username):
+ self.verify_admin(authtoken)
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 200e797..e99499a 100644
--- a/static/js/admin.js
+++ b/static/js/admin.js
@@ -24,7 +24,26 @@ Object.defineProperty(String.prototype, 'hashCode', {
}
});
-function render_table(data) {
+async function get_secret(user) {
+
+ const r = await fetch(admin_api_path + 'get_secret', {
+ method: 'POST',
+ body: JSON.stringify({
+ uuid: user.uuid
+ }),
+ });
+ console.log(r);
+
+ if (r.status !== 200) {
+ console.log("oh no");
+ return;
+ }
+
+ const data = await r.json();
+ return data[user.uuid]
+}
+
+async function render_table(data) {
const users = Object.values(data.users);
const newusername = document.querySelector("#newusername");
@@ -65,9 +84,13 @@ function render_table(data) {
plusbutton = clone.querySelector("#plusbutton")
;
- name.innerText = user.name;
cur.innerText = user.score;
max.innerText = user.maxscore;
+
+ const secret = await get_secret(user);
+ name.innerText = user.name;
+ name.href = `../dealer/${secret}`;
+ // console.log(secret);
//const button = document.getElementById("plusbutton");
|