Dear Boss
Please review my code below, which successfully retrieves the user ID and password from the user and displays the page. However, I have incorporated additional code to enable access for other users, yet it has not yielded the expected outcomes. I would like my code to display the page according to the user role. I would be grateful if you could provide the appropriate code to ensure that all users can view and access their assigned pages.
import streamlit as st
username =''
password = ''
if 'logged_in' not in st.session_state:
st.session_state['logged_in'] = False
def login_page():
st.title('Login')
username = st.text_input('Username')
password = st.text_input('Password', type='password')
if st.button('Login'):
if username == 'u' and password == 'p':
st.session_state['logged_in'] = True
st.header('Muhammad is the best')
st.success('Logged in successfully!')
st.rerun()
elif username == 'o' and password == 'p':
st.session_state['logged_in'] = True
st.header('Muhammad is the best')
st.success('Logged in successfully!')
st.rerun()
else:
st.error('Invalid credentials.')
def dashboard_page():
st.title('Dashboard')
st.write('Welcome to your dashboard!')
def dashboard_page111():
st.title('Tesing page d')
st.write('testing page =============!')
def admin_page():
st.title('Admin Panel')
st.write('Admin-only content.')
pages = [
st.Page(login_page, title='Login'),
]
if st.session_state['logged_in']:
if username == 'u' and password == 'p':
pages.append(st.Page(dashboard_page, title='Dashboard'))
elif username == 'o' and password == 'p':
pages.append(st.Page(dashboard_page111, title='Dashboard'))
# Conditionally add admin page
if st.session_state.get('is_admin'): # Assuming you set this after login
pages.append(st.Page(admin_page, title='Admin'))
current_page = st.navigation(pages)
current_page.run()