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)