diff --git a/files/__main__.py b/files/__main__.py index 313a1fec9..b69194017 100644 --- a/files/__main__.py +++ b/files/__main__.py @@ -103,8 +103,6 @@ def before_request(): if 'iphone' in ua or 'ipad' in ua or 'ipod' in ua or 'mac os' in ua or ' firefox/' in ua: g.inferior_browser = True else: g.inferior_browser = False - g.timestamp = int(time.time()) - @app.teardown_appcontext def teardown_request(error): diff --git a/files/helpers/jinja2.py b/files/helpers/jinja2.py index 1cec597c8..d9e33cb6f 100644 --- a/files/helpers/jinja2.py +++ b/files/helpers/jinja2.py @@ -50,4 +50,4 @@ def timestamp(timestamp): @app.context_processor def inject_constants(): - return {"environ":environ, "SITE":SITE, "SITE_NAME":SITE_NAME, "SITE_FULL":SITE_FULL, "AUTOJANNY_ID":AUTOJANNY_ID, "NOTIFICATIONS_ID":NOTIFICATIONS_ID, "PUSHER_ID":PUSHER_ID, "CC":CC, "CC_TITLE":CC_TITLE, "listdir":listdir, "MOOSE_ID":MOOSE_ID, "AEVANN_ID":AEVANN_ID, "PIZZASHILL_ID":PIZZASHILL_ID, "config":app.config.get, "DEFAULT_COLOR":DEFAULT_COLOR, "COLORS":COLORS, "ADMIGGERS":ADMIGGERS, "datetime":datetime} \ No newline at end of file + return {"environ":environ, "SITE":SITE, "SITE_NAME":SITE_NAME, "SITE_FULL":SITE_FULL, "AUTOJANNY_ID":AUTOJANNY_ID, "NOTIFICATIONS_ID":NOTIFICATIONS_ID, "PUSHER_ID":PUSHER_ID, "CC":CC, "CC_TITLE":CC_TITLE, "listdir":listdir, "MOOSE_ID":MOOSE_ID, "AEVANN_ID":AEVANN_ID, "PIZZASHILL_ID":PIZZASHILL_ID, "config":app.config.get, "DEFAULT_COLOR":DEFAULT_COLOR, "COLORS":COLORS, "ADMIGGERS":ADMIGGERS, "datetime":datetime, "time":time} \ No newline at end of file diff --git a/files/helpers/wrappers.py b/files/helpers/wrappers.py index 2b314eee5..c625426c1 100644 --- a/files/helpers/wrappers.py +++ b/files/helpers/wrappers.py @@ -7,14 +7,17 @@ from random import randint def get_logged_in_user(): if not session.get("session_id"): + session.permanent = True session["session_id"] = secrets.token_hex(49) + timestamp = int(time.time()) + sessions = cache.get(f'{SITE}_sessions') or {} - sessions[session["session_id"]] = g.timestamp + sessions[session["session_id"]] = timestamp counter = 0 for val in sessions.values(): - if g.timestamp - val < 15*60: + if timestamp - val < 15*60: counter += 1 g.counter = counter @@ -75,7 +78,6 @@ def auth_desired(f): def auth_required(f): def wrapper(*args, **kwargs): - g.timestamp = int(time.time()) v = get_logged_in_user() if not v: abort(401) diff --git a/files/routes/admin.py b/files/routes/admin.py index 6931d7cfa..53be8a068 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -31,7 +31,6 @@ def merge(v, id1, id2): if v.id != AEVANN_ID: abort(403) if time.time() - session.get('verified', 0) > 3: - session.pop("session_id", None) session.pop("lo_user", None) path = request.path qs = urlencode(dict(request.values)) @@ -91,7 +90,6 @@ def merge_all(v, id): if v.id != AEVANN_ID: abort(403) if time.time() - session.get('verified', 0) > 3: - session.pop("session_id", None) session.pop("lo_user", None) path = request.path qs = urlencode(dict(request.values)) diff --git a/files/routes/login.py b/files/routes/login.py index d8ae9dae2..43f53b2c6 100644 --- a/files/routes/login.py +++ b/files/routes/login.py @@ -139,8 +139,6 @@ def login_post(): else: abort(400) - session.permanent = True - session["session_id"] = token_hex(49) session["lo_user"] = account.id session["login_nonce"] = account.login_nonce if account.id == AEVANN_ID: session["verified"] = time.time() @@ -173,7 +171,6 @@ def me(v): @auth_required def logout(v): - session.pop("session_id", None) session.pop("lo_user", None) return {"message": "Logout successful!"} @@ -364,8 +361,6 @@ def sign_up_post(v): send_notification(new_user.id, WELCOME_MSG) - session.permanent = True - session["session_id"] = token_hex(49) session["lo_user"] = new_user.id g.db.commit() diff --git a/files/templates/home.html b/files/templates/home.html index 8729553df..373122e1d 100644 --- a/files/templates/home.html +++ b/files/templates/home.html @@ -207,7 +207,7 @@ {% endif %} -{% if request.path == '/' and g.timestamp > session.get('tooltip_last_dismissed',0)+60*60*24*30 and not g.webview %} +{% if request.path == '/' and time.time() > session.get('tooltip_last_dismissed',0)+60*60*24*30 and not g.webview %}