osbm commited on
Commit
2a2a63d
·
1 Parent(s): fabb286

refactor login logic to improve user feedback and session handling

Browse files
Files changed (1) hide show
  1. app.py +19 -18
app.py CHANGED
@@ -116,24 +116,25 @@ def update_vote(
116
 
117
 
118
 
119
- if 'loggedin' not in st.session_state:
120
- st.session_state['loggedin'] = 'false'
121
- # st.session_state["vote-osman-image-path"] = "None"
122
-
123
- with st.form("login"):
124
- username = st.selectbox("Select voter", voters)
125
- password = st.text_input("Password (get password from [email protected])", type="password")
126
- submitted = st.form_submit_button("Login")
127
-
128
- if submitted or st.session_state['loggedin'] == 'true':
129
- if not password == os.environ.get("app_password"):
130
- st.error("The password you entered is incorrect")
131
- st.stop()
132
- else:
133
- st.success("Welcome, " + username)
134
- st.write("You are now logged in")
135
- st.session_state['loggedin'] = 'true'
136
-
 
137
  image_path = get_one_from_queue(username)
138
 
139
  with st.form("images", clear_on_submit=True):
 
116
 
117
 
118
 
119
+ if 'loggedin' not in st.session_state: # user is not logged in
120
+ st.error("You are not logged in")
121
+ with st.form("login"):
122
+ username = st.selectbox("Select voter", voters)
123
+ password = st.text_input("Password (get password from [email protected])", type="password")
124
+ submitted = st.form_submit_button("Login")
125
+
126
+ if submitted: # submitted password
127
+ if not password == os.environ.get("app_password"): # password is incorrect
128
+ st.error("The password you entered is incorrect")
129
+ st.stop()
130
+ else: # password is correct
131
+ st.success("Welcome, " + username)
132
+ st.write("You are now logged in")
133
+ st.session_state['loggedin'] = username
134
+
135
+ else: # logged in
136
+ username = st.session_state['loggedin']
137
+ st.success(f"Welcome, {username}")
138
  image_path = get_one_from_queue(username)
139
 
140
  with st.form("images", clear_on_submit=True):