JSenkCC commited on
Commit
02d5a36
·
verified ·
1 Parent(s): bbf2bcc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -41
app.py CHANGED
@@ -49,48 +49,56 @@ def main():
49
  st.session_state.authenticated = False
50
  if "username" not in st.session_state:
51
  st.session_state.username = None
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
 
53
- # Central login/register interface
54
- if not st.session_state.authenticated:
55
- st.subheader("Please Log In or Register to Continue")
56
- auth_mode = st.radio("Choose an Option", ["Log In", "Register"], horizontal=True)
57
-
58
- if auth_mode == "Log In":
59
- st.subheader("Log In")
60
- username = st.text_input("Username", key="login_username")
61
- password = st.text_input("Password", type="password", key="login_password")
62
-
63
- if st.button("Log In"):
64
- if authenticate_user(username, password):
65
- st.success(f"Welcome back, {username}!")
66
- st.session_state.authenticated = True
67
- st.session_state.username = username
68
- st.experimental_rerun()
69
- else:
70
- st.error("Invalid username or password. Please try again.")
71
-
72
- elif auth_mode == "Register":
73
- st.subheader("Register")
74
- username = st.text_input("Create Username", key="register_username")
75
- password = st.text_input("Create Password", type="password", key="register_password")
76
-
77
- if st.button("Register"):
78
- if username and password:
79
- add_user(username, password)
80
- st.success("Account created successfully! You can now log in.")
81
- else:
82
- st.error("Please fill in all fields.")
83
- else:
84
- # Authenticated user workspace with sidebar
85
- st.sidebar.title(f"Hello, {st.session_state.username}!")
86
- if st.sidebar.button("Log Out"):
87
- st.session_state.authenticated = False
88
- st.session_state.username = None
89
- st.experimental_rerun()
90
-
91
- # Main content area
92
- st.subheader(f"Welcome to your workspace, {st.session_state.username}!")
93
- st.write("This is your personal workspace. All your saved work will appear here.")
94
 
95
  if __name__ == "__main__":
96
  main()
@@ -98,3 +106,4 @@ if __name__ == "__main__":
98
 
99
 
100
 
 
 
49
  st.session_state.authenticated = False
50
  if "username" not in st.session_state:
51
  st.session_state.username = None
52
+ if "page" not in st.session_state:
53
+ st.session_state.page = "login"
54
+
55
+ # Navigation logic
56
+ if st.session_state.page == "login":
57
+ login_page()
58
+ elif st.session_state.page == "workspace":
59
+ workspace_page()
60
+
61
+ def login_page():
62
+ st.subheader("Please Log In or Register to Continue")
63
+ auth_mode = st.radio("Choose an Option", ["Log In", "Register"], horizontal=True)
64
+
65
+ if auth_mode == "Log In":
66
+ st.subheader("Log In")
67
+ username = st.text_input("Username", key="login_username")
68
+ password = st.text_input("Password", type="password", key="login_password")
69
+
70
+ if st.button("Log In"):
71
+ if authenticate_user(username, password):
72
+ st.success(f"Welcome back, {username}!")
73
+ st.session_state.authenticated = True
74
+ st.session_state.username = username
75
+ st.session_state.page = "workspace"
76
+ else:
77
+ st.error("Invalid username or password. Please try again.")
78
+
79
+ elif auth_mode == "Register":
80
+ st.subheader("Register")
81
+ username = st.text_input("Create Username", key="register_username")
82
+ password = st.text_input("Create Password", type="password", key="register_password")
83
+
84
+ if st.button("Register"):
85
+ if username and password:
86
+ add_user(username, password)
87
+ st.success("Account created successfully! You can now log in.")
88
+ else:
89
+ st.error("Please fill in all fields.")
90
+
91
+ def workspace_page():
92
+ # Sidebar with logout button
93
+ st.sidebar.title(f"Hello, {st.session_state.username}!")
94
+ if st.sidebar.button("Log Out"):
95
+ st.session_state.authenticated = False
96
+ st.session_state.username = None
97
+ st.session_state.page = "login"
98
 
99
+ # Main content area
100
+ st.subheader(f"Welcome to your workspace, {st.session_state.username}!")
101
+ st.write("This is your personal workspace. All your saved work will appear here.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
102
 
103
  if __name__ == "__main__":
104
  main()
 
106
 
107
 
108
 
109
+