From a6114990de592917e3e426532197f0934da16402 Mon Sep 17 00:00:00 2001 From: Michael Coughlin Date: Thu, 11 Jun 2026 09:51:47 -0500 Subject: [PATCH] anonymous login --- app/flow.py | 1 + app/handlers/base.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/app/flow.py b/app/flow.py index 73ae3d0..00fab50 100644 --- a/app/flow.py +++ b/app/flow.py @@ -18,6 +18,7 @@ class Flow: port : str Port on which the message bus is listening for messages. """ + def __init__( self, host=cfg["hosts.message_bus"], diff --git a/app/handlers/base.py b/app/handlers/base.py index 9ed6fd9..fa23d1f 100644 --- a/app/handlers/base.py +++ b/app/handlers/base.py @@ -44,6 +44,21 @@ def user_id(self): return self.get_secure_cookie("user_id") def get_current_user(self): + user = self._signed_in_user() + if user is not None: + return user + # Anonymous read-only access (opt-in via app.anonymous_access): serve the + # configured "View only" account when nobody is signed in. + cfg = self.application.cfg + if not cfg.get("app.anonymous_access", False): + return None + username = cfg.get("app.anonymous_user") or "anonymous" + with DBSession() as session: + return session.scalars( + sqlalchemy.select(User).where(User.username == username) + ).first() + + def _signed_in_user(self): if self.user_id() is None: return user_id = int(self.user_id())