import streamlit as st from utils.auth import login_user, signup_user, init_db # Initialize the database init_db() st.set_page_config(page_title="🏸 BharatPlay", layout="wide") # Session management 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("

🏸 BharatPlay

", unsafe_allow_html=True) st.markdown("

Explore & Contribute to Indian Games

", 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 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() 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 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() # Add in your app.py, after login section 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"): st.session_state.authenticated = False st.session_state.username = None st.rerun() 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"""

{cat['icon']} {cat['name']}

{cat['desc']}

""", unsafe_allow_html=True) # 🟢 Button placed inside the card st.page_link(f"pages/{cat['page']}.py", label=f"➡️ Explore {cat['name']}", use_container_width=True) st.markdown("
", unsafe_allow_html=True)