Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,18 +1,37 @@
|
|
1 |
import streamlit as st
|
|
|
|
|
2 |
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
-
#@st.cache_data(experimental_allow_widgets=True) # π Set the parameter
|
11 |
def main():
|
12 |
-
st.title('User Data
|
13 |
|
14 |
-
#
|
15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
# Input fields with emojis
|
18 |
new_email = st.text_input("π§ Email Address", value=cached_data['email'])
|
@@ -25,16 +44,21 @@ def main():
|
|
25 |
else:
|
26 |
new_password = st.text_input("π Password", value=cached_data['password'], type='password')
|
27 |
|
28 |
-
# Update
|
29 |
if new_email != cached_data['email'] or new_phone != cached_data['phone'] or new_password != cached_data['password']:
|
30 |
-
cached_data
|
31 |
-
cached_data
|
32 |
-
|
33 |
-
st.success("Data updated and cached!")
|
34 |
|
35 |
-
st.write("
|
36 |
st.json(cached_data)
|
37 |
|
38 |
-
#
|
39 |
-
if
|
40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
+
import os
|
3 |
+
import json
|
4 |
|
5 |
+
def save_user_data(email, data):
|
6 |
+
"""Save user data to a file named after the user's email."""
|
7 |
+
with open(f"{email}.txt", "w") as file:
|
8 |
+
file.write(json.dumps(data))
|
9 |
+
|
10 |
+
def load_user_data(email):
|
11 |
+
"""Load user data from a file named after the user's email."""
|
12 |
+
try:
|
13 |
+
with open(f"{email}.txt", "r") as file:
|
14 |
+
return json.loads(file.read())
|
15 |
+
except FileNotFoundError:
|
16 |
+
return {'email': '', 'phone': '', 'password': ''}
|
17 |
+
|
18 |
+
def list_saved_users():
|
19 |
+
"""List all files (users) with saved states."""
|
20 |
+
return [f[:-4] for f in os.listdir() if f.endswith('.txt')]
|
21 |
|
|
|
22 |
def main():
|
23 |
+
st.title('User Data Management')
|
24 |
|
25 |
+
# Sidebar for selecting a user file
|
26 |
+
st.sidebar.title("Saved Users")
|
27 |
+
saved_users = list_saved_users()
|
28 |
+
selected_user = st.sidebar.selectbox("Select a user", options=saved_users)
|
29 |
+
|
30 |
+
# Load data for the selected user
|
31 |
+
if selected_user:
|
32 |
+
cached_data = load_user_data(selected_user)
|
33 |
+
else:
|
34 |
+
cached_data = {'email': '', 'phone': '', 'password': ''}
|
35 |
|
36 |
# Input fields with emojis
|
37 |
new_email = st.text_input("π§ Email Address", value=cached_data['email'])
|
|
|
44 |
else:
|
45 |
new_password = st.text_input("π Password", value=cached_data['password'], type='password')
|
46 |
|
47 |
+
# Update and save data if changes are made
|
48 |
if new_email != cached_data['email'] or new_phone != cached_data['phone'] or new_password != cached_data['password']:
|
49 |
+
cached_data = {'email': new_email, 'phone': new_phone, 'password': new_password}
|
50 |
+
save_user_data(new_email, cached_data)
|
51 |
+
st.success("Data updated and saved!")
|
|
|
52 |
|
53 |
+
st.write("Current Data:")
|
54 |
st.json(cached_data)
|
55 |
|
56 |
+
# Password Reset Simulation
|
57 |
+
if st.sidebar.button("Reset Password"):
|
58 |
+
reset_email = st.sidebar.text_input("Enter email for password reset")
|
59 |
+
if reset_email in saved_users:
|
60 |
+
reset_data = load_user_data(reset_email)
|
61 |
+
reset_data['password'] = 'new_password' # Reset password
|
62 |
+
save_user_data(reset_email, reset_data)
|
63 |
+
st.sidebar.success(f"Password reset for {reset_email}")
|
64 |
+
|