Compare commits

..

No commits in common. "f1d98376d482f26d2da8f48361af5febb48ed11c" and "39301255a88525d3140a5bf9c3b874cdc7a9deb3" have entirely different histories.

2 changed files with 23 additions and 13 deletions

View File

@ -10,16 +10,22 @@
<body>
this is the base site
<a href="/newclient">Log in</a>
<br>
<input id="username" type="text" placeholder="Joe"/>
<button id="btn_register">idk</button>
<input id="some_input" type="text" placeholder="dunno"/>
<button id="btn_dunno">idk</button>
<script>
document.getElementById("btn_register").onclick = function (e) {
let username = document.getElementById("username").value;
document.getElementById("btn_dunno").onclick = async function (e) {
let text = document.getElementById("some_input").value;
let data = {"username": text};
window.location.replace(`/register/${encodeURIComponent(username)}`)
await fetch('/newclient', {
method: 'POST',
body: JSON.stringify(data),
})
};
</script>
</body>

20
main.py
View File

@ -1,6 +1,5 @@
import aiohttp.web
import traceback
import urllib.parse
from model import Model
@ -32,7 +31,7 @@ def get_client(request: aiohttp.web.Request):
async def handler(request: aiohttp.web.Request):
# this handler prevents people missing trailing slashes
client = get_client(request)
raise aiohttp.web.HTTPFound(f"{client}/")
raise aiohttp.web.HTTPFound(f"/{client}/")
@routes.get(CLIENT_REGEX + '/')
@ -96,14 +95,19 @@ async def handler(request):
return aiohttp.web.FileResponse('index.html')
@routes.get('/register/{username}')
@routes.post('/newclient')
async def handler(request):
model = request.app['model']
username = request.match_info.get('username', 'Joe')
username = urllib.parse.unquote(username)
client = model.create_client(username)
raise aiohttp.web.HTTPFound(f"/{client}/")
data = await request.json()
username = data.get("username")
print(f"{username=}")
if username:
client = model.create_client(username)
print(f"werked?")
raise aiohttp.web.HTTPFound(f"/{client}/")
print(f"werked?")
else:
raise aiohttp.web.HTTPFound(f"/newclient")
if __name__ == '__main__':