Compare commits

..

No commits in common. "405e92bb5fa3567ec00105216ec3f1a7bf2461e6" and "b015543cc54f11167140e065bc27af1b874087eb" have entirely different histories.

3 changed files with 5 additions and 26 deletions

View File

@ -33,9 +33,9 @@
</head>
<body>
<div id="container"></div>
this is the base site
<a href="/newclient">Log in</a>
</div>
</body>
</html>

16
main.py
View File

@ -15,15 +15,9 @@ def get_client(request: aiohttp.web.Request):
client = request.match_info.get("client", None)
model = request.app['model']
if not client:
print('[get_client] client is not set, wtf')
if not client or not model.exists_client(client):
raise aiohttp.web.HTTPBadRequest()
if not model.exists_client(client):
print(f'[get_client] model does not know {client=}')
raise aiohttp.web.HTTPBadRequest()
return client
@ -92,14 +86,6 @@ async def handler(request):
return aiohttp.web.FileResponse('index.html')
@routes.get('/newclient')
async def handler(request):
model = request.app['model']
client = model.create_client()
raise aiohttp.web.HTTPFound(f"/{client}/")
if __name__ == '__main__':
app = aiohttp.web.Application()
app.add_routes(routes)

View File

@ -5,13 +5,6 @@ import os
import datetime
def generate_random_id(_s=set()):
while (new_id := base64.b32encode(bytearray(random.randint(0, 0xFF) for _ in range(10)))[:16].decode().lower()) in _s:
pass
_s.add(new_id)
return new_id
class Model:
def __init__(self, filename = "tehmodel.json"):
self.sockets = {} # mapping: client -> socket
@ -55,13 +48,13 @@ class Model:
return clientid in self.model["clients"]
def create_client(self) -> str:
clientname = generate_random_id()
clientname = base64.b32encode(bytearray(random.randint(0, 0xFF) for _ in range(10)))[:16].decode().lower()
newclient = {"id": clientname}
self.model["clients"][clientname] = newclient
return clientname
def create_session(self) -> str:
sessionname = generate_random_id()
sessionname = base64.b32encode(bytearray(random.randint(0, 0xFF) for _ in range(10)))[:16].decode().lower()
newsession = {"id": sessionname, "clients": []}
self.model["sessions"][sessionname] = newsession
return sessionname