forked from ahmedfgad/GeneticAlgorithmPython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
48 lines (37 loc) · 1.38 KB
/
app.py
File metadata and controls
48 lines (37 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
"""
Example Streamlit entry point demonstrating multi-user auth.
Run: streamlit run app.py
"""
from __future__ import annotations
import streamlit as st
from auth.auth_handler import AuthHandler
from utils.auth_utils import get_current_user, get_current_user_fernet, require_login
st.set_page_config(page_title="App", page_icon="🔐", layout="centered")
auth = AuthHandler()
tab_login, tab_register = st.tabs(["Login", "Register"])
with tab_login:
name, status, username = auth.render_login()
if status:
st.success(f"Welcome, {name}!")
user = get_current_user()
if user:
st.write(f"User ID: {user.user_id} | Email: {user.email}")
if st.button("Logout"):
auth.render_logout()
with tab_register:
if auth.render_register(pre_authorized=None):
st.success("Account created. Please log in.")
st.rerun()
st.divider()
if auth.is_authenticated():
user = require_login(show_login=False)
st.subheader("Protected area")
st.write(f"Hello **{user.name}** — your data is encrypted with your per-user key.")
try:
fernet = get_current_user_fernet()
token = fernet.encrypt(b"demo").decode()
st.code(f"Sample encrypt OK (token prefix): {token[:20]}...")
except Exception as exc:
st.error(f"Encryption check failed: {exc}")
else:
st.info("Log in to access protected content.")