first commit
This commit is contained in:
38
streamlit_dashboard/streamlit_pages/admin_streamlit_page.py
Normal file
38
streamlit_dashboard/streamlit_pages/admin_streamlit_page.py
Normal file
@@ -0,0 +1,38 @@
|
||||
import streamlit as st
|
||||
from streamlit_authenticator import Authenticate
|
||||
|
||||
# Imports from this module
|
||||
from streamlit_constants import ADMIN_ROLE_NAME
|
||||
from streamlit_constants import USDA_API_KEY, CENSUS_YEAR
|
||||
from page_classes.naics_report_page_class import NaicsReportPage
|
||||
from page_classes.report_comparer_page_class import ComparerPage
|
||||
from page_classes.page_class_constants import REPORT_CONFIGS
|
||||
from page_classes.admin_panel_page_class import AdminPanelPage
|
||||
|
||||
authenticator:Authenticate = st.session_state.get('authenticator')
|
||||
|
||||
st.set_page_config(layout='wide')
|
||||
|
||||
PAGE_CLASS_STATE_KEY = 'admin_page_session_state'
|
||||
|
||||
if st.session_state.get('authentication_status'):
|
||||
user_roles = st.session_state.get('roles', [])
|
||||
if user_roles and ADMIN_ROLE_NAME in user_roles:
|
||||
authenticator.logout()
|
||||
st.write(f'Welcome *{st.session_state.get("name")}*')
|
||||
|
||||
if PAGE_CLASS_STATE_KEY in st.session_state:
|
||||
admin_page = st.session_state[PAGE_CLASS_STATE_KEY]
|
||||
else:
|
||||
admin_page = AdminPanelPage()
|
||||
st.session_state[PAGE_CLASS_STATE_KEY] = admin_page
|
||||
|
||||
admin_page.render(st.container())
|
||||
else:
|
||||
authenticator.logout()
|
||||
st.write(f"You do not have the '{ADMIN_ROLE_NAME}' role required to access this page.")
|
||||
st.write(f"See https://github.com/mkhorasani/Streamlit-Authenticator?tab=readme-ov-file#3-creating-a-config-file for how to modify the authentication config file to add this role to an account.")
|
||||
elif st.session_state.get('authentication_status') is False:
|
||||
st.error('Username/password is incorrect')
|
||||
elif st.session_state.get('authentication_status') is None:
|
||||
st.warning('Please enter your username and password')
|
||||
Reference in New Issue
Block a user