users here now

remotes/1693045480750635534/spooky-22
Aevann1 2022-05-24 22:19:18 +02:00
parent ca18dc8bdd
commit 2b9dcb0c6a
3 changed files with 17 additions and 3 deletions

View File

@ -5,6 +5,21 @@ from files.__main__ import db_session
from random import randint
def get_logged_in_user():
if not session.get("session_id"):
session["session_id"] = secrets.token_hex(49)
sessions = cache.get(f'{SITE}_sessions') or {}
sessions[session["session_id"]] = g.timestamp
counter = 0
for val in sessions.values():
if g.timestamp - val < 60:
counter += 1
g.counter = counter
cache.set(f'{SITE}_sessions', sessions)
if not (hasattr(g, 'db') and g.db): g.db = db_session()
v = None

View File

@ -169,9 +169,6 @@ def notifications(v):
@auth_desired
def front_all(v, sub=None, subdomain=None):
if g.webview and not session.get("session_id"):
session["session_id"] = secrets.token_hex(49)
if not v and not request.path.startswith('/logged_out'): return redirect(f"/logged_out{request.full_path}")
if v and request.path.startswith('/logged_out'): return redirect(request.full_path.replace('/logged_out',''))

View File

@ -13,6 +13,8 @@
<img class="mb-4" alt="sidebar image" role="button" data-bs-toggle="modal" data-bs-target="#expandImageModal" onclick="expandDesktopImage('{{image}}')" loading="lazy" src="{{image}}" width=100%>
{% endif %}
{{g.counter}} USERS HERE NOW<br><br>
{% if sub %}
{% if sub.sidebar_html %}
<div class="mb-4">{{sub.sidebar_html|safe}}</div>