Add getsecret method
This commit is contained in:
parent
1138badacc
commit
504b85b7ed
@ -57,7 +57,9 @@
|
|||||||
|
|
||||||
<template>
|
<template>
|
||||||
<tr class="row">
|
<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="cur"></td>
|
||||||
<td class="score" id="max"></td>
|
<td class="score" id="max"></td>
|
||||||
<td class="score" id="incr">
|
<td class="score" id="incr">
|
||||||
|
16
model.py
16
model.py
@ -41,8 +41,8 @@ class Model(object):
|
|||||||
self.secretlookup = { self.users[uuid].get_secret() : uuid for uuid in self.users }
|
self.secretlookup = { self.users[uuid].get_secret() : uuid for uuid in self.users }
|
||||||
|
|
||||||
print(f'Admin Token: {hashlib.sha256(SECRET.encode() + b"admintoken").hexdigest()}')
|
print(f'Admin Token: {hashlib.sha256(SECRET.encode() + b"admintoken").hexdigest()}')
|
||||||
for user in self.users.values():
|
#for user in self.users.values():
|
||||||
print(f"{user.name.rjust(25)} -> /dealer/{user.get_secret()}")
|
# print(f"{user.name.rjust(25)} -> /dealer/{user.get_secret()}")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -50,7 +50,7 @@ class Model(object):
|
|||||||
model = {
|
model = {
|
||||||
"users": { uuid: self.users[uuid].to_json() for uuid in self.users },
|
"users": { uuid: self.users[uuid].to_json() for uuid in self.users },
|
||||||
}
|
}
|
||||||
print(model)
|
#print(model)
|
||||||
return model
|
return model
|
||||||
|
|
||||||
def verify_user(self, authtoken):
|
def verify_user(self, authtoken):
|
||||||
@ -99,11 +99,19 @@ class Model(object):
|
|||||||
# Admin API Methods
|
# 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
|
@ApiMethod
|
||||||
async def add_user(self, authtoken, username):
|
async def add_user(self, authtoken, username):
|
||||||
|
self.verify_admin(authtoken)
|
||||||
if username == "":
|
if username == "":
|
||||||
raise Exception("Username can't be blank!")
|
raise Exception("Username can't be blank!")
|
||||||
self.verify_admin(authtoken)
|
|
||||||
newuser = User(username = username)
|
newuser = User(username = username)
|
||||||
self.users[newuser.uuid] = newuser
|
self.users[newuser.uuid] = newuser
|
||||||
|
|
||||||
|
@ -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 users = Object.values(data.users);
|
||||||
|
|
||||||
const newusername = document.querySelector("#newusername");
|
const newusername = document.querySelector("#newusername");
|
||||||
@ -65,10 +84,14 @@ function render_table(data) {
|
|||||||
plusbutton = clone.querySelector("#plusbutton")
|
plusbutton = clone.querySelector("#plusbutton")
|
||||||
;
|
;
|
||||||
|
|
||||||
name.innerText = user.name;
|
|
||||||
cur.innerText = user.score;
|
cur.innerText = user.score;
|
||||||
max.innerText = user.maxscore;
|
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");
|
//const button = document.getElementById("plusbutton");
|
||||||
|
|
||||||
plusbutton.addEventListener("click", async () => {
|
plusbutton.addEventListener("click", async () => {
|
||||||
|
Loading…
Reference in New Issue
Block a user