Spaces:
Sleeping
Sleeping
File size: 3,909 Bytes
98c1f3f 078eba7 266b81f 4821065 e4f0fcc a880b1e 4821065 e4f0fcc e4d5175 e4f0fcc 4821065 e4d5175 e4f0fcc 4821065 e4f0fcc 4821065 788d3a5 4821065 788d3a5 4821065 e4f0fcc e4d5175 e4f0fcc e4d5175 e4f0fcc f021f20 e4f0fcc 4821065 3090d3d e4f0fcc | 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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | # โ
app.py(Updated with persistent login)
import os
os.environ["STREAMLIT_HOME"] = "/tmp/.streamlit"
import streamlit as st
from auth import login_user, signup_user, save_login, load_login, logout_user
st.set_page_config(page_title="๐ธ BharatPlay", layout="wide")
# Restore login from file if exists
saved_user = load_login()
if saved_user and "authenticated" not in st.session_state:
st.session_state.authenticated = True
st.session_state.username = saved_user
# Session management defaults
if "authenticated" not in st.session_state:
st.session_state.authenticated = False
if "username" not in st.session_state:
st.session_state.username = None
# Header
st.markdown("""
<div style='text-align:center;'>
<h1 style='color:#6A1B9A;'>๐ธ BharatPlay</h1>
<h3>Explore & Contribute to Indian Games</h3>
</div>
""", unsafe_allow_html=True)
st.markdown("---")
# Login/signup form
if not st.session_state.authenticated:
tab1, tab2 = st.tabs(["๐ Login", "๐ Sign Up"])
with tab1:
with st.form("login_form"):
username = st.text_input("Username")
password = st.text_input("Password", type="password")
if st.form_submit_button("Login"):
if login_user(username, password):
st.session_state.authenticated = True
st.session_state.username = username
save_login(username)
st.success(f"โ
Welcome, {username}!")
st.rerun()
else:
st.error("โ Invalid credentials.")
with tab2:
with st.form("signup_form"):
new_user = st.text_input("Choose Username")
new_pass = st.text_input("Choose Password", type="password")
if st.form_submit_button("Sign Up"):
if new_user and new_pass:
if signup_user(new_user, new_pass):
st.success("๐ Account created! Please log in.")
else:
st.error("โ ๏ธ Username already exists.")
else:
st.warning("Please fill both fields.")
st.stop()
# Sidebar account controls
with st.sidebar:
if st.session_state.authenticated:
st.markdown("### ๐ง Account")
st.success(f"โ
Logged in as `{st.session_state.username}`")
if st.button("๐ช Logout"):
logout_user()
st.session_state.authenticated = False
st.session_state.username = None
st.rerun()
# Game Categories UI
st.markdown("### ๐ฎ Choose a Game Category:")
categories = [
{"name": "Indoor", "icon": "๐ฒ", "desc": "Games played indoors.", "page": "1_Indoor"},
{"name": "Outdoor", "icon": "๐", "desc": "Games played outdoors.", "page": "2_Outdoor"},
{"name": "Traditional", "icon": "๐ช", "desc": "Culturally rooted Indian games.", "page": "3_Traditional"},
{"name": "Martial Arts", "icon": "๐ฅ", "desc": "Combat-based sports.", "page": "4_Martial_Arts"},
{"name": "Upload History", "icon": "๐", "desc": "View all uploads.", "page": "5_Upload_history"},
]
cols = st.columns(2)
for i, cat in enumerate(categories):
with cols[i % 2]:
with st.container():
st.markdown(f"""
<div style='background-color:#f3e5f5;padding:20px;border-radius:15px;
box-shadow:0 0 10px #bbb;margin-bottom:10px;'>
<h3 style='color:#4A148C;margin-bottom:10px;'>{cat['icon']} {cat['name']}</h3>
<p style='margin-bottom:20px;'>{cat['desc']}</p>
""", unsafe_allow_html=True)
# Explore button inside the box
st.page_link(f"pages/{cat['page']}.py", label=f"โก๏ธ Explore {cat['name']}", use_container_width=True)
st.markdown("</div>", unsafe_allow_html=True)
|