artintel235 commited on
Commit
ce1a6c4
·
verified ·
1 Parent(s): 0d7b164

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -84
app.py CHANGED
@@ -1,87 +1,12 @@
1
- import streamlit as st
 
2
 
3
- # Initialize session state for user data and authentication
4
- if "users" not in st.session_state:
5
- st.session_state.users = {} # Store registered users (username: password)
6
- if "logged_in" not in st.session_state:
7
- st.session_state.logged_in = False
8
- if "current_user" not in st.session_state:
9
- st.session_state.current_user = None
10
 
11
- # Registration function
12
- def register(username, password):
13
- if username in st.session_state.users:
14
- st.error("Username already exists. Please choose a different username.")
15
- else:
16
- st.session_state.users[username] = password
17
- st.success("Registration successful! Please log in.")
18
-
19
- # Login function
20
- def login(username, password):
21
- if username in st.session_state.users and st.session_state.users[username] == password:
22
- st.session_state.logged_in = True
23
- st.session_state.current_user = username
24
- st.success("Logged in successfully!")
25
- else:
26
- st.error("Invalid username or password.")
27
-
28
- # Logout function
29
- def logout():
30
- st.session_state.logged_in = False
31
- st.session_state.current_user = None
32
- st.info("Logged out successfully!")
33
-
34
- # Registration form
35
- def registration_form():
36
- with st.form("Registration"):
37
- st.subheader("Register")
38
- username = st.text_input("Username (min 5 characters)", key="reg_username")
39
- password = st.text_input("Password (min 6 characters)", type="password", key="reg_password")
40
- submit_button = st.form_submit_button("Register")
41
-
42
- if submit_button:
43
- if len(username) < 5:
44
- st.error("Username must be at least 5 characters long.")
45
- elif len(password) < 6:
46
- st.error("Password must be at least 6 characters long.")
47
- else:
48
- register(username, password)
49
-
50
- # Login form
51
- def login_form():
52
- with st.form("Login"):
53
- st.subheader("Login")
54
- username = st.text_input("Username", key="login_username")
55
- password = st.text_input("Password", type="password", key="login_password")
56
- submit_button = st.form_submit_button("Login")
57
-
58
- if submit_button:
59
- if len(username) < 5:
60
- st.error("Username must be at least 5 characters long.")
61
- elif len(password) < 6:
62
- st.error("Password must be at least 6 characters long.")
63
- else:
64
- login(username, password)
65
-
66
- # Main app screen (after login)
67
- def main_app():
68
- st.subheader(f"Welcome, {st.session_state.current_user}!")
69
- st.write("Enter a name below to get a greeting.")
70
-
71
- # Input field for name
72
- name = st.text_input("Enter a name", key="name_input")
73
-
74
- # Display greeting in real-time
75
- if name:
76
- st.write(f"Hi {name}!")
77
-
78
- # Logout button
79
- if st.button("Logout"):
80
- logout()
81
-
82
- # Render the appropriate screen based on login status
83
- if st.session_state.logged_in:
84
- main_app()
85
  else:
86
- registration_form()
87
- login_form()
 
1
+ import os
2
+ import json
3
 
4
+ # Retrieve the JSON string from the secret
5
+ json_str = os.getenv("FIREBASE_CREDENTIALS")
 
 
 
 
 
6
 
7
+ # Convert the string back to a JSON object
8
+ if json_str:
9
+ firebase_creds = json.loads(json_str)
10
+ print("Firebase credentials loaded successfully!")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  else:
12
+ print("Failed to load Firebase credentials.")