Add getsecret method

This commit is contained in:
Kai Vogelgesang 2020-07-18 02:57:13 +02:00
parent 1138badacc
commit 504b85b7ed
3 changed files with 42 additions and 9 deletions

View File

@ -57,7 +57,9 @@
<template>
<tr class="row">
<td class="score" id="name"></td>
<td class="score">
<a id="name"></a>
</td>
<td class="score" id="cur"></td>
<td class="score" id="max"></td>
<td class="score" id="incr">

View File

@ -41,8 +41,8 @@ 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()}")
@ -50,7 +50,7 @@ class Model(object):
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

View File

@ -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,10 +84,14 @@ 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");
plusbutton.addEventListener("click", async () => {