CF cookie: improve reliability

pull/50/head
justcool393 2022-12-06 14:28:45 -06:00
parent f8cfe7cf82
commit c7fbc39e5f
3 changed files with 9 additions and 4 deletions

View File

@ -45,7 +45,7 @@ if not IS_LOCALHOST:
app.config["SESSION_COOKIE_NAME"] = "session_" + environ.get("SITE_NAME").strip().lower()
app.config['MAX_CONTENT_LENGTH'] = 100 * 1024 * 1024
app.config["SESSION_COOKIE_SAMESITE"] = "Lax"
app.config["PERMANENT_SESSION_LIFETIME"] = 60 * 60 * 24 * 365
app.config["PERMANENT_SESSION_LIFETIME"] = SESSION_LIFETIME
app.config['SESSION_REFRESH_EACH_REQUEST'] = False
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

View File

@ -68,6 +68,8 @@ REDDIT_NOTIFS_CACHE_KEY = "reddit_notifications"
MARSEYS_CACHE_KEY = "marseys"
EMOJIS_CACHE_KEY = "emojis"
SESSION_LIFETIME = 60 * 60 * 24 * 365
CASINO_RELEASE_DAY = 1662825600
if SITE_NAME == 'rDrama': patron = 'Paypig'

View File

@ -75,9 +75,12 @@ def _set_cloudflare_cookie(response:Response) -> None:
if not g.desires_auth: return
if not CLOUDFLARE_AVAILABLE or not CLOUDFLARE_COOKIE_VALUE: return
logged_in = bool(getattr(g, 'v', None))
response.set_cookie("lo", CLOUDFLARE_COOKIE_VALUE if logged_in else '',
max_age=60*60*24*365 if logged_in else 1, samesite="Lax",
domain=app.config["COOKIE_DOMAIN"])
if not logged_in and request.cookies.get("lo"):
response.delete_cookie("lo", domain=app.config["COOKIE_DOMAIN"], samesite="Lax")
elif logged_in and not request.cookies.get("lo"):
response.set_cookie("lo", CLOUDFLARE_COOKIE_VALUE if logged_in else '',
max_age=SESSION_LIFETIME, samesite="Lax",
domain=app.config["COOKIE_DOMAIN"])
def _fix_frozen_sessions(response:Response) -> None:
'''