Update app.py
Browse files
app.py
CHANGED
|
@@ -40,17 +40,17 @@ app = demo.app
|
|
| 40 |
def cookie(req: Request) -> str:
|
| 41 |
return req.cookies.get("vesta_session", "")
|
| 42 |
|
| 43 |
-
@app.get("/")
|
| 44 |
-
async def
|
| 45 |
t = cookie(req)
|
| 46 |
if check_token(t):
|
| 47 |
return RedirectResponse(url="/px/")
|
| 48 |
-
return HTMLResponse(LOGIN
|
| 49 |
|
| 50 |
@app.post("/login")
|
| 51 |
async def do_login(user: str = Form(...), passw: str = Form(...)):
|
| 52 |
if user.lower() != "admin" or passw != ADMIN_TOKEN:
|
| 53 |
-
return RedirectResponse(url="/?error=1", status_code=303)
|
| 54 |
token = make_token()
|
| 55 |
r = RedirectResponse(url="/px/", status_code=303)
|
| 56 |
r.set_cookie("vesta_session", token, max_age=86400, path="/", httponly=True)
|
|
@@ -58,7 +58,7 @@ async def do_login(user: str = Form(...), passw: str = Form(...)):
|
|
| 58 |
|
| 59 |
@app.get("/logout")
|
| 60 |
async def logout():
|
| 61 |
-
r = RedirectResponse(url="/")
|
| 62 |
r.delete_cookie("vesta_session", path="/")
|
| 63 |
return r
|
| 64 |
|
|
@@ -66,7 +66,7 @@ async def logout():
|
|
| 66 |
async def proxy(req: Request, rest: str = ""):
|
| 67 |
t = cookie(req)
|
| 68 |
if not check_token(t):
|
| 69 |
-
return RedirectResponse(url="/")
|
| 70 |
path = "/" + rest
|
| 71 |
try:
|
| 72 |
async with httpx.AsyncClient(timeout=30) as c:
|
|
|
|
| 40 |
def cookie(req: Request) -> str:
|
| 41 |
return req.cookies.get("vesta_session", "")
|
| 42 |
|
| 43 |
+
@app.get("/login")
|
| 44 |
+
async def login_get(req: Request):
|
| 45 |
t = cookie(req)
|
| 46 |
if check_token(t):
|
| 47 |
return RedirectResponse(url="/px/")
|
| 48 |
+
return HTMLResponse(LOGIN)
|
| 49 |
|
| 50 |
@app.post("/login")
|
| 51 |
async def do_login(user: str = Form(...), passw: str = Form(...)):
|
| 52 |
if user.lower() != "admin" or passw != ADMIN_TOKEN:
|
| 53 |
+
return RedirectResponse(url="/login?error=1", status_code=303)
|
| 54 |
token = make_token()
|
| 55 |
r = RedirectResponse(url="/px/", status_code=303)
|
| 56 |
r.set_cookie("vesta_session", token, max_age=86400, path="/", httponly=True)
|
|
|
|
| 58 |
|
| 59 |
@app.get("/logout")
|
| 60 |
async def logout():
|
| 61 |
+
r = RedirectResponse(url="/login")
|
| 62 |
r.delete_cookie("vesta_session", path="/")
|
| 63 |
return r
|
| 64 |
|
|
|
|
| 66 |
async def proxy(req: Request, rest: str = ""):
|
| 67 |
t = cookie(req)
|
| 68 |
if not check_token(t):
|
| 69 |
+
return RedirectResponse(url="/login")
|
| 70 |
path = "/" + rest
|
| 71 |
try:
|
| 72 |
async with httpx.AsyncClient(timeout=30) as c:
|