Spaces:
Sleeping
Sleeping
refactor login logic to improve user feedback and session handling
Browse files
app.py
CHANGED
@@ -116,24 +116,25 @@ def update_vote(
|
|
116 |
|
117 |
|
118 |
|
119 |
-
if 'loggedin' not in st.session_state:
|
120 |
-
st.
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
submitted
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
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):
|