Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 16 additions & 43 deletions src/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,53 +35,26 @@ def check_password():
)

auth0_logged = False
password_logged = False

# check if we have logged on with a password, if we havent show auth0
if ("password_correct" not in st.session_state) or (not st.session_state["password_correct"]):
show_auth0 = True
else:
show_auth0 = False

with col2:
if show_auth0:
# show auth0 log in
try:
user_info = login_button(clientId=clientId, domain=domain,debug_logs=True)
except Exception as e:
st.text('Could not run auth')
logger.error(f'Could not run auth {e}')

if user_info is None:
st.text('No user info')

if user_info:
if '@openclimatefix.' not in user_info['email']:
st.text('This is only available to OCF members')
else:
auth0_logged = True

# if we have not logged in with auth0
if not auth0_logged:
if "password_correct" not in st.session_state:
# First run, show input for password.
st.text_input(
"Password", type="password", on_change=password_entered, key="password", autocomplete="current-password"
)

elif not st.session_state["password_correct"]:
# Password not correct, show input + error.
st.text_input(
"Password", type="password", on_change=password_entered, key="password", autocomplete="current-password"
)
st.error("😕 Password incorrect")

# show auth0 log in
try:
user_info = login_button(clientId=clientId, domain=domain)
except Exception as e:
st.text('Could not run auth')
logger.error(f'Could not run auth {e}')

if user_info is None:
st.text('No user info')

if user_info:
if '@openclimatefix.' not in user_info['email']:
st.text('This is only available to OCF members')
else:
# Password correct, show success message.
st.success("🔒 Password correct")
password_logged = True
auth0_logged = True

if auth0_logged or password_logged:
if auth0_logged:
st.text('Hi ' + user_info['email'])
return True
else:
st.text('Please log in')
Expand Down
Loading