Spaces:
Runtime error
Runtime error
Updated the security model to support multiple passwords for different users, so I can grant it to someone and revoke if needed.
Browse files- src/st_helpers.py +25 -1
src/st_helpers.py
CHANGED
@@ -1,5 +1,24 @@
|
|
1 |
import streamlit as st
|
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
def st_setup(page_title: str, layout: str = 'wide'):
|
4 |
"""
|
5 |
Sets up standard outline (wide layout), checks for logged in status and then
|
@@ -9,6 +28,11 @@ def st_setup(page_title: str, layout: str = 'wide'):
|
|
9 |
:return: bool - logged in status
|
10 |
"""
|
11 |
st.set_page_config(page_title=page_title, layout=layout)
|
|
|
|
|
|
|
|
|
|
|
12 |
with st.sidebar:
|
13 |
st.image('img/uob-logo.png', width=200)
|
14 |
|
@@ -25,7 +49,7 @@ def st_setup(page_title: str, layout: str = 'wide'):
|
|
25 |
st.write('### Log in')
|
26 |
pw = st.text_input(type='password', label='Password')
|
27 |
if st.button('Log in'):
|
28 |
-
if pw
|
29 |
st.session_state[logged_in]=True
|
30 |
st.rerun()
|
31 |
else:
|
|
|
1 |
import streamlit as st
|
2 |
|
3 |
+
|
4 |
+
def login(pw: str) -> bool:
|
5 |
+
"""
|
6 |
+
Convenience wrapper for login functionality. Has side effect of storing the logged in
|
7 |
+
user name in the session state
|
8 |
+
:param pw: Password to attempt login
|
9 |
+
:return: True/False if logged in
|
10 |
+
"""
|
11 |
+
pw_users = st.secrets['app_password'].split(';')
|
12 |
+
for pu in pw_users:
|
13 |
+
split_point=pu.find('(')
|
14 |
+
pu_password = pu[0:split_point]
|
15 |
+
if pu_password == pw:
|
16 |
+
pu_user = pu[split_point + 1: -1]
|
17 |
+
st.session_state['username'] = pu_user
|
18 |
+
return True
|
19 |
+
return False
|
20 |
+
|
21 |
+
|
22 |
def st_setup(page_title: str, layout: str = 'wide'):
|
23 |
"""
|
24 |
Sets up standard outline (wide layout), checks for logged in status and then
|
|
|
28 |
:return: bool - logged in status
|
29 |
"""
|
30 |
st.set_page_config(page_title=page_title, layout=layout)
|
31 |
+
|
32 |
+
username='username'
|
33 |
+
if username in st.session_state:
|
34 |
+
st.markdown(f'<div style="float: right;">Logged in as <b>{st.session_state[username]}</b></span>', unsafe_allow_html=True)
|
35 |
+
|
36 |
with st.sidebar:
|
37 |
st.image('img/uob-logo.png', width=200)
|
38 |
|
|
|
49 |
st.write('### Log in')
|
50 |
pw = st.text_input(type='password', label='Password')
|
51 |
if st.button('Log in'):
|
52 |
+
if login(pw):
|
53 |
st.session_state[logged_in]=True
|
54 |
st.rerun()
|
55 |
else:
|