thomasht86 commited on
Commit
484c3e0
·
verified ·
1 Parent(s): c543bf7

deploy at 2024-08-24 19:52:56.044132

Browse files
Files changed (1) hide show
  1. main.py +17 -3
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
- print(f"Session after setting auth: {sess}")
 
444
  response = RedirectResponse("/admin", status_code=303)
445
- print(f"Cookies being set: {response.headers.get('Set-Cookie')}")
 
 
 
 
 
 
 
 
 
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(