Spaces:
Running
Running
deploy at 2024-08-25 18:23:28.592643
Browse files
main.py
CHANGED
|
@@ -151,6 +151,7 @@ with open("main.py") as f:
|
|
| 151 |
|
| 152 |
# Sesskey
|
| 153 |
sess_key_path = "session/.sesskey"
|
|
|
|
| 154 |
# Make sure session directory exists
|
| 155 |
os.makedirs("session", exist_ok=True)
|
| 156 |
|
|
@@ -205,7 +206,9 @@ app, rt = fast_app(
|
|
| 205 |
hdrs=headers,
|
| 206 |
#middleware=middlewares,
|
| 207 |
key_fname=sess_key_path,
|
| 208 |
-
samesite="none"
|
|
|
|
|
|
|
| 209 |
)
|
| 210 |
|
| 211 |
# Add this function for debugging
|
|
@@ -443,7 +446,7 @@ async def login(sess, request: Request):
|
|
| 443 |
password = form.get("pwd")
|
| 444 |
|
| 445 |
if username == ADMIN_NAME and compare_digest(ADMIN_PWD.encode("utf-8"), password.encode("utf-8")):
|
| 446 |
-
sess['auth'
|
| 447 |
return RedirectResponse("/admin", status_code=303)
|
| 448 |
|
| 449 |
return RedirectResponse("/login?error=True", status_code=303)
|
|
@@ -451,7 +454,8 @@ async def login(sess, request: Request):
|
|
| 451 |
|
| 452 |
@app.route("/logout")
|
| 453 |
async def logout(sess):
|
| 454 |
-
sess
|
|
|
|
| 455 |
return RedirectResponse("/")
|
| 456 |
|
| 457 |
|
|
@@ -649,8 +653,8 @@ def download_csv(request: Request):
|
|
| 649 |
|
| 650 |
|
| 651 |
@app.route("/admin")
|
| 652 |
-
async def admin(sess):
|
| 653 |
-
auth = sess.get('auth', False)
|
| 654 |
if not auth:
|
| 655 |
print(f"Not authenticated: {auth}")
|
| 656 |
return RedirectResponse("/login", status_code=303)
|
|
|
|
| 151 |
|
| 152 |
# Sesskey
|
| 153 |
sess_key_path = "session/.sesskey"
|
| 154 |
+
SESSION_KEY = "session_"
|
| 155 |
# Make sure session directory exists
|
| 156 |
os.makedirs("session", exist_ok=True)
|
| 157 |
|
|
|
|
| 206 |
hdrs=headers,
|
| 207 |
#middleware=middlewares,
|
| 208 |
key_fname=sess_key_path,
|
| 209 |
+
samesite="none",
|
| 210 |
+
secure=True, # Add this line
|
| 211 |
+
httponly=True, # Add this line
|
| 212 |
)
|
| 213 |
|
| 214 |
# Add this function for debugging
|
|
|
|
| 446 |
password = form.get("pwd")
|
| 447 |
|
| 448 |
if username == ADMIN_NAME and compare_digest(ADMIN_PWD.encode("utf-8"), password.encode("utf-8")):
|
| 449 |
+
sess[SESSION_KEY] = {'auth': True}
|
| 450 |
return RedirectResponse("/admin", status_code=303)
|
| 451 |
|
| 452 |
return RedirectResponse("/login?error=True", status_code=303)
|
|
|
|
| 454 |
|
| 455 |
@app.route("/logout")
|
| 456 |
async def logout(sess):
|
| 457 |
+
if SESSION_KEY in sess:
|
| 458 |
+
del sess[SESSION_KEY]
|
| 459 |
return RedirectResponse("/")
|
| 460 |
|
| 461 |
|
|
|
|
| 653 |
|
| 654 |
|
| 655 |
@app.route("/admin")
|
| 656 |
+
async def admin(request, sess):
|
| 657 |
+
auth = sess.get(SESSION_KEY, {}).get('auth', False)
|
| 658 |
if not auth:
|
| 659 |
print(f"Not authenticated: {auth}")
|
| 660 |
return RedirectResponse("/login", status_code=303)
|