charantejapolavarapu commited on
Commit
7904b3d
·
verified ·
1 Parent(s): 7b769b4

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +22 -15
src/streamlit_app.py CHANGED
@@ -9,7 +9,7 @@ import datetime
9
  import hashlib
10
  import os
11
 
12
- # --- Page Config ---
13
  st.set_page_config(
14
  page_title="భారత్ పల్స్ (BharatPulse) - వార్తలు",
15
  page_icon="📰",
@@ -17,8 +17,8 @@ st.set_page_config(
17
  initial_sidebar_state="expanded"
18
  )
19
 
20
- # --- User Auth Utilities ---
21
- USERS_FILE = "users.json"
22
 
23
  def hash_password(password):
24
  return hashlib.sha256(password.encode()).hexdigest()
@@ -52,15 +52,16 @@ def register_user(username, email, password, location=""):
52
  save_users(users)
53
  return True, "Registration successful"
54
 
55
- # --- Login/Register Page ---
56
  if "logged_in" not in st.session_state:
57
  st.session_state.logged_in = False
58
  st.session_state.username = ""
 
 
 
59
 
60
  def show_login_page():
61
  st.title("🔐 లాగిన్ (Login)")
62
- st.write("దయచేసి మీ ఖాతా వివరాలను నమోదు చేయండి.")
63
-
64
  username = st.text_input("వినియోగదారు పేరు (Username)")
65
  password = st.text_input("పాస్‌వర్డ్ (Password)", type="password")
66
 
@@ -78,7 +79,6 @@ def show_login_page():
78
  st.error("చెల్లని లాగిన్ వివరాలు. దయచేసి మళ్లీ ప్రయత్నించండి.")
79
 
80
  st.info("మీకు ఖాతా లేనట్లయితే, దయచేసి క్రింద నమోదు చేసుకోండి.")
81
-
82
  with st.expander("👉 ఖాతా రిజిస్ట్రేషన్ (Register New Account)"):
83
  new_username = st.text_input("కొత్త వినియోగదారు పేరు", key="register_username")
84
  new_email = st.text_input("ఇమెయిల్", key="register_email")
@@ -91,22 +91,29 @@ def show_login_page():
91
  else:
92
  st.error(message)
93
 
94
- # If not logged in, show login page and stop app
95
  if not st.session_state.logged_in:
96
  show_login_page()
97
  st.stop()
98
 
99
- # --- LOGOUT Button ---
100
  st.sidebar.title("భారత్ పల్స్ - సెట్టింగ్‌లు")
101
  if st.sidebar.button("లాగ్ అవుట్ (Logout)"):
102
  st.session_state.logged_in = False
103
  st.session_state.username = ""
104
- st.session_state.user_email = ""
105
- st.session_state.user_location = ""
106
- st.session_state.account_creation_date = "N/A"
107
  st.rerun()
108
 
109
- # Continue with full BharatPulse app...
110
- # (Insert your BharatPulse main app code here – you already provided it)
 
 
 
 
 
 
 
 
 
 
 
111
 
112
- # ✅ Tip: Use st.session_state.username, user_email, etc., in Profile tab
 
9
  import hashlib
10
  import os
11
 
12
+ # --- CRITICAL: Set page config FIRST ---
13
  st.set_page_config(
14
  page_title="భారత్ పల్స్ (BharatPulse) - వార్తలు",
15
  page_icon="📰",
 
17
  initial_sidebar_state="expanded"
18
  )
19
 
20
+ # --- User Authentication Logic ---
21
+ USERS_FILE = "/tmp/users.json" # Writable location on all platforms
22
 
23
  def hash_password(password):
24
  return hashlib.sha256(password.encode()).hexdigest()
 
52
  save_users(users)
53
  return True, "Registration successful"
54
 
55
+ # --- Login UI ---
56
  if "logged_in" not in st.session_state:
57
  st.session_state.logged_in = False
58
  st.session_state.username = ""
59
+ st.session_state.user_email = ""
60
+ st.session_state.user_location = ""
61
+ st.session_state.account_creation_date = "N/A"
62
 
63
  def show_login_page():
64
  st.title("🔐 లాగిన్ (Login)")
 
 
65
  username = st.text_input("వినియోగదారు పేరు (Username)")
66
  password = st.text_input("పాస్‌వర్డ్ (Password)", type="password")
67
 
 
79
  st.error("చెల్లని లాగిన్ వివరాలు. దయచేసి మళ్లీ ప్రయత్నించండి.")
80
 
81
  st.info("మీకు ఖాతా లేనట్లయితే, దయచేసి క్రింద నమోదు చేసుకోండి.")
 
82
  with st.expander("👉 ఖాతా రిజిస్ట్రేషన్ (Register New Account)"):
83
  new_username = st.text_input("కొత్త వినియోగదారు పేరు", key="register_username")
84
  new_email = st.text_input("ఇమెయిల్", key="register_email")
 
91
  else:
92
  st.error(message)
93
 
94
+ # --- Check login state ---
95
  if not st.session_state.logged_in:
96
  show_login_page()
97
  st.stop()
98
 
99
+ # LOGOUT BUTTON in Sidebar
100
  st.sidebar.title("భారత్ పల్స్ - సెట్టింగ్‌లు")
101
  if st.sidebar.button("లాగ్ అవుట్ (Logout)"):
102
  st.session_state.logged_in = False
103
  st.session_state.username = ""
 
 
 
104
  st.rerun()
105
 
106
+ # Load rest of BharatPulse app
107
+ st.title("భారత్ పల్స్ (BharatPulse) 🇮🇳")
108
+ st.subheader(f"హాయ్ {st.session_state.username} 🌟 - మీరు లాగిన్ అయ్యారు.")
109
+ st.markdown("మీ స్థానిక మరియు జాతీయ వార్తల వన్-స్టాప్ మూలం (Your one-stop source for local and national news)")
110
+
111
+ st.info("👉 Full BharatPulse features will load below. You can now access tabs like Headlines, Location, City Search, and Profile.")
112
+
113
+ # 🔻 OPTIONAL: Place your full BharatPulse app code from before here
114
+ # 🧠 You can copy-paste the rest of your previous implementation starting from:
115
+ # main_tabs = st.tabs([...])
116
+ # and everything below it
117
+
118
+ st.success("✅ ఇప్పుడు మీరు అప్లికేషన్‌ను పూర్తిగా ఉపయోగించవచ్చు!")
119