Compare commits
No commits in common. "f1d98376d482f26d2da8f48361af5febb48ed11c" and "39301255a88525d3140a5bf9c3b874cdc7a9deb3" have entirely different histories.
f1d98376d4
...
39301255a8
16
index.html
16
index.html
@ -10,16 +10,22 @@
|
|||||||
<body>
|
<body>
|
||||||
this is the base site
|
this is the base site
|
||||||
|
|
||||||
|
<a href="/newclient">Log in</a>
|
||||||
|
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
<input id="username" type="text" placeholder="Joe"/>
|
<input id="some_input" type="text" placeholder="dunno"/>
|
||||||
<button id="btn_register">idk</button>
|
<button id="btn_dunno">idk</button>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
document.getElementById("btn_register").onclick = function (e) {
|
document.getElementById("btn_dunno").onclick = async function (e) {
|
||||||
let username = document.getElementById("username").value;
|
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>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
20
main.py
20
main.py
@ -1,6 +1,5 @@
|
|||||||
import aiohttp.web
|
import aiohttp.web
|
||||||
import traceback
|
import traceback
|
||||||
import urllib.parse
|
|
||||||
|
|
||||||
from model import Model
|
from model import Model
|
||||||
|
|
||||||
@ -32,7 +31,7 @@ def get_client(request: aiohttp.web.Request):
|
|||||||
async def handler(request: aiohttp.web.Request):
|
async def handler(request: aiohttp.web.Request):
|
||||||
# this handler prevents people missing trailing slashes
|
# this handler prevents people missing trailing slashes
|
||||||
client = get_client(request)
|
client = get_client(request)
|
||||||
raise aiohttp.web.HTTPFound(f"{client}/")
|
raise aiohttp.web.HTTPFound(f"/{client}/")
|
||||||
|
|
||||||
|
|
||||||
@routes.get(CLIENT_REGEX + '/')
|
@routes.get(CLIENT_REGEX + '/')
|
||||||
@ -96,14 +95,19 @@ async def handler(request):
|
|||||||
return aiohttp.web.FileResponse('index.html')
|
return aiohttp.web.FileResponse('index.html')
|
||||||
|
|
||||||
|
|
||||||
@routes.get('/register/{username}')
|
@routes.post('/newclient')
|
||||||
async def handler(request):
|
async def handler(request):
|
||||||
model = request.app['model']
|
model = request.app['model']
|
||||||
username = request.match_info.get('username', 'Joe')
|
data = await request.json()
|
||||||
username = urllib.parse.unquote(username)
|
username = data.get("username")
|
||||||
|
print(f"{username=}")
|
||||||
client = model.create_client(username)
|
if username:
|
||||||
raise aiohttp.web.HTTPFound(f"/{client}/")
|
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__':
|
if __name__ == '__main__':
|
||||||
|
Loading…
Reference in New Issue
Block a user