Spaces:
Sleeping
Sleeping
Create backup.app2.py
Browse files- backup.app2.py +64 -0
backup.app2.py
ADDED
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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, or create a new file if it doesn't exist."""
|
12 |
+
if not os.path.isfile(f"{email}.txt"):
|
13 |
+
return {'email': '', 'phone': '', 'password': ''}
|
14 |
+
with open(f"{email}.txt", "r") as file:
|
15 |
+
return json.loads(file.read())
|
16 |
+
|
17 |
+
def list_saved_users():
|
18 |
+
"""List all files (users) with saved states."""
|
19 |
+
return [f[:-4] for f in os.listdir() if f.endswith('.txt')]
|
20 |
+
|
21 |
+
def main():
|
22 |
+
st.title('User Data Management')
|
23 |
+
|
24 |
+
# Sidebar for selecting a user file
|
25 |
+
st.sidebar.title("Saved Users")
|
26 |
+
saved_users = list_saved_users()
|
27 |
+
selected_user = st.sidebar.selectbox("Select a user", options=['New User'] + saved_users)
|
28 |
+
|
29 |
+
# Load or initialize data
|
30 |
+
if selected_user and selected_user != 'New User':
|
31 |
+
cached_data = load_user_data(selected_user)
|
32 |
+
else:
|
33 |
+
cached_data = {'email': '', 'phone': '', 'password': ''}
|
34 |
+
|
35 |
+
# Input fields with emojis
|
36 |
+
new_email = st.text_input("π§ Email Address", value=cached_data['email'])
|
37 |
+
new_phone = st.text_input("π± Mobile Phone", value=cached_data['phone'])
|
38 |
+
show_password = st.checkbox("Show password")
|
39 |
+
if show_password:
|
40 |
+
new_password = st.text_input("π Password", value=cached_data['password'])
|
41 |
+
else:
|
42 |
+
new_password = st.text_input("π Password", value=cached_data['password'], type='password')
|
43 |
+
|
44 |
+
# Save data when changes are made
|
45 |
+
if new_email and (new_email != cached_data['email'] or new_phone != cached_data['phone'] or new_password != cached_data['password']):
|
46 |
+
cached_data = {'email': new_email, 'phone': new_phone, 'password': new_password}
|
47 |
+
save_user_data(new_email, cached_data)
|
48 |
+
st.sidebar.success("Data updated and saved!")
|
49 |
+
|
50 |
+
st.write("Current Data:")
|
51 |
+
st.json(cached_data)
|
52 |
+
|
53 |
+
# Password Reset Simulation
|
54 |
+
if st.sidebar.button("Reset Password"):
|
55 |
+
reset_email = st.sidebar.text_input("Enter email for password reset")
|
56 |
+
if reset_email and reset_email in saved_users:
|
57 |
+
reset_data = load_user_data(reset_email)
|
58 |
+
reset_data['password'] = 'new_password' # Reset password
|
59 |
+
save_user_data(reset_email, reset_data)
|
60 |
+
st.sidebar.success(f"Password reset for {reset_email}")
|
61 |
+
|
62 |
+
# Run the app
|
63 |
+
if __name__ == "__main__":
|
64 |
+
main()
|