Insightlab / utils /menu.py
Maheshsr's picture
updating the title
bd36982
import streamlit as st
from pages import login
from loguru import logger
APP_TITLE = ' '#'Revenue Cycle Management'
def _check_password():
"""Authenticate user and manage login state."""
if st.session_state.get("authenticated"):
return True
# Create a container for the entire page
container = st.container()
# Add a logo and title within the container
with container:
st.image("logo.png", width=200)
st.title("Welcome to Insights-Lab")
# Create a tabbed interface for login and signup
tabs = st.tabs(["Login", "Signup", "Resend Code"])
confirm_code_button = None
with tabs[0]:
# Login form
with st.form("login_form"):
login_user = st.text_input("Username",value = "maheshsr")
password = st.text_input("Password", type="password", value="Test@123")
login_button = st.form_submit_button("Login")
with tabs[1]:
# Signup form
with st.form("sign_up_form"):
name = st.text_input("Name")
email = st.text_input("Email")
new_username = st.text_input("New Username")
new_password = st.text_input("New Password", type="password")
confirm_password = st.text_input("Confirm Password", type="password")
signup_button = st.form_submit_button("Signup")
signup_code = st.text_input("OTP")
signup_code_button = st.form_submit_button("Confirm")
with tabs[2]:
# Resend Code
with st.form("resend_code"):
username = st.text_input("Username")
resend_code_button = st.form_submit_button("Resend Code")
confirm_code = st.text_input("OTP")
confirm_code_button = st.form_submit_button("Confirm")
# Add a placeholder for login/signup results
if login_button:
logger.info("Login button clicked.")
# login.login(login_user, password)
if login.login(login_user, password):
st.session_state.authenticated = True
# composer.run()
st.rerun()
elif signup_button:
logger.info("Signup button clicked.")
form_validation = login.signup_validation(new_password, confirm_password, name, email, new_username)
if form_validation:
login.signup(new_password, name, email, new_username)
elif resend_code_button:
logger.info("Resend code button clicked.")
login.resend_sign_up_code(username)
elif confirm_code_button:
logger.info("Confirm code button clicked.")
login.confirm_sign_up_code(username, confirm_code)
elif signup_code_button:
logger.info("Signup code button clicked.")
login.confirm_sign_up_code(new_username, signup_code)
return False
def _authenticated_menu():
if "page" not in st.session_state:
st.session_state.page = "composer"
st.switch_page("pages/composer.py")
with st.sidebar:
st.logo('logo.png')
st.image('insightlab_logo.png')
st.subheader(APP_TITLE, divider='blue')
st.header(" ")
st.sidebar.page_link("pages/composer.py", label="Dataset Composer")
st.session_state.page = "composer"
st.sidebar.page_link("pages/profiler.py",label="Data Profiler")
st.session_state.page = "profiler"
st.sidebar.page_link("pages/visualize.py", label="Data Visualizer")
st.session_state.page = "visualize"
st.sidebar.page_link("pages/designer.py", label="Insight Designer")
st.session_state.page = "designer"
st.sidebar.page_link("pages/automator.py", label="Insight Library")
st.session_state.page = "library"
if(st.session_state.userId=="c4686458-10a1-7096-10be-c5966f270129"):
st.sidebar.page_link("pages/logger.py", label="Logger")
st.session_state.page = "logger"
st.sidebar.divider()
if st.sidebar.button("Logout"):
_logout()
def _unauthenticated_menu():
logger.info("Rendering unauthenticated menu.")
pass
def _logout():
"""Log out the current user."""
logger.info("User logged out.")
st.session_state.clear()
st.success("You have been logged out successfully.")
st.rerun()
def menu():
if not _check_password():
logger.info("not logined")
_unauthenticated_menu()
st.stop()
else:
_authenticated_menu()
def menu_with_redirect():
if not _check_password():
st.switch_page("app.py")
menu()