# -*- coding: utf-8 -*- """Microsoft Entra ID sign-in gate using Streamlit's native OIDC auth. Replaces the Flask `@login_required` / identity.web flow from the PTT-SIGN-IN app. Reuses the same Azure App Registration, configured in `.streamlit/secrets.toml` under the [auth] table. Requires Streamlit >= 1.42. """ from __future__ import annotations import streamlit as st # Self-contained styling for the login "access pass". Inherits the app's fonts # and page gradient; defines its own card so the screen reads as one intentional # object rather than a button on a panel. _LOGIN_CSS = """ """ def _is_logged_in() -> bool: try: return bool(st.user.is_logged_in) except Exception: # st.user raises if [auth] is missing/misconfigured in secrets.toml. return False def _auth_configured() -> bool: """True if an [auth] provider is configured in secrets.toml.""" try: return "auth" in st.secrets except Exception: return False def require_login() -> None: """Block the app until the user signs in with their PTT (Entra) account. Call once, right after the page CSS is injected and before any app content. Renders a themed sign-in screen and st.stop()s when the user is not authenticated; returns normally once they are. """ if _is_logged_in(): return # ── Login screen ──────────────────────────────────────────────────────── # Signature element: an "access pass" — a ticket card echoing the app's hero, # with a gradient stub, a perforated tear-line, and two punched notches. You # present a pass to enter the document system. Everything else stays quiet. st.markdown(_LOGIN_CSS, unsafe_allow_html=True) with st.container(key="login_card"): st.markdown( """
ลงชื่อเข้าใช้ด้วยบัญชี PTT
เพื่อสร้างและดาวน์โหลดเอกสาร