Spaces:
Running
Running
deploy at 2024-08-24 19:52:56.044132
Browse files
main.py
CHANGED
@@ -440,9 +440,19 @@ def post(login: Login, sess):
|
|
440 |
if not compare_digest(ADMIN_PWD.encode("utf-8"), login.pwd.encode("utf-8")):
|
441 |
# Incorrect password - add error message
|
442 |
return RedirectResponse("/login?error=True", status_code=303)
|
443 |
-
|
|
|
444 |
response = RedirectResponse("/admin", status_code=303)
|
445 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
446 |
return response
|
447 |
|
448 |
|
@@ -647,7 +657,11 @@ def download_csv(auth):
|
|
647 |
|
648 |
|
649 |
@app.get("/admin")
|
650 |
-
def get_admin(auth, page: int = 1):
|
|
|
|
|
|
|
|
|
651 |
limit = 15
|
652 |
offset = (page - 1) * limit
|
653 |
total_queries_result = list(
|
|
|
440 |
if not compare_digest(ADMIN_PWD.encode("utf-8"), login.pwd.encode("utf-8")):
|
441 |
# Incorrect password - add error message
|
442 |
return RedirectResponse("/login?error=True", status_code=303)
|
443 |
+
|
444 |
+
sess["auth"] = True
|
445 |
response = RedirectResponse("/admin", status_code=303)
|
446 |
+
|
447 |
+
# Explicitly set the session cookie
|
448 |
+
response.set_cookie(
|
449 |
+
key="session",
|
450 |
+
value=sess,
|
451 |
+
httponly=True,
|
452 |
+
secure=True,
|
453 |
+
samesite="Lax"
|
454 |
+
)
|
455 |
+
|
456 |
return response
|
457 |
|
458 |
|
|
|
657 |
|
658 |
|
659 |
@app.get("/admin")
|
660 |
+
def get_admin(auth, sess, page: int = 1):
|
661 |
+
# Check if the user is authenticated
|
662 |
+
if not sess.get("auth"):
|
663 |
+
return RedirectResponse("/login", status_code=303)
|
664 |
+
|
665 |
limit = 15
|
666 |
offset = (page - 1) * limit
|
667 |
total_queries_result = list(
|