awacke1 commited on
Commit
79b82de
Β·
verified Β·
1 Parent(s): 5e2ad97

Create backup.app3.py

Browse files
Files changed (1) hide show
  1. backup.app3.py +68 -0
backup.app3.py ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 containing '@' in filename."""
19
+ return [f[:-4] for f in os.listdir() if f.endswith('.txt') and '@' in f]
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
+ new_password = st.text_input("πŸ”‘ Password", value=cached_data['password'], type='password')
39
+
40
+ # Save data when changes are made
41
+ if new_email and (new_email != cached_data['email'] or new_phone != cached_data['phone'] or new_password != cached_data['password']):
42
+ cached_data = {'email': new_email, 'phone': new_phone, 'password': new_password}
43
+ save_user_data(new_email, cached_data)
44
+ st.sidebar.success("Data updated and saved!")
45
+
46
+ # Show email link with GET parameter
47
+ if new_email:
48
+ st.write(f"Link for this user: https://huggingface.co/spaces/awacke1/Streamlit-Memory-Cache-Resource-and-Data/?email={new_email}`")
49
+ st.session_state['last_email'] = new_email
50
+
51
+ # Display current data without password
52
+ display_data = cached_data.copy()
53
+ display_data['password'] = '*****' # Hide the password
54
+ st.write("Current Data:")
55
+ st.json(display_data)
56
+
57
+ # Password Reset Simulation
58
+ if st.sidebar.button("Reset Password"):
59
+ reset_email = st.sidebar.text_input("Enter email for password reset")
60
+ if reset_email and reset_email in saved_users:
61
+ reset_data = load_user_data(reset_email)
62
+ reset_data['password'] = 'new_password' # Reset password
63
+ save_user_data(reset_email, reset_data)
64
+ st.sidebar.success(f"Password reset for {reset_email}")
65
+
66
+ # Run the app
67
+ if __name__ == "__main__":
68
+ main()