import streamlit as st
import streamlit.components.v1 as components
from streamlit_navigation_bar import st_navbar
from streamlit_option_menu import option_menu
import time
from app import *
from FirebaseDatabase.FirebaseDB import *
import re
##########################################authentication
import yaml
from yaml.loader import SafeLoader
##########################################
def store_email_in_browser(email):
js = f"""
"""
st.markdown(js, unsafe_allow_html=True)
introBar7Style = """
"""
@st.dialog("Login")
def loginForm():
# with open('config.yaml') as file:
# config = yaml.load(file, Loader=SafeLoader)
# stauth.Hasher.hash_passwords(config['credentials'])
# st.session_state.authenticator = stauth.Authenticate(
# config['credentials'],
# config['cookie']['name'],
# config['cookie']['key'],
# config['cookie']['expiry_days'],
# auto_hash = False
# )
# st.session_state.login = st.session_state.authenticator.login(key="initialLogin")
with st.form(key="LoginForm", clear_on_submit=False):
email = st.text_input(label = "Email")
password = st.text_input(label= "Password", type = "password")
margin, buttoncol = st.columns([0.92,0.08])
loginSubmit = st.form_submit_button(label = "SignIn", use_container_width=True)
if loginSubmit:
with st.spinner("Verifying credentials..."):
if email == "" or password == "":
st.error('Please enter your username or password')
else:
db = firebaseDB()
st.session_state.database = db
if db.get_user(email, password):
st.session_state.logged_in = True
store_email_in_browser(email)
# if st.session_state['authentication_status']:
# st.session_state.logged_in = True
#st.switch_page(dashboard)
st.switch_page(AIManagement)
else:
st.error('Username/password is incorrect')
#st.session_state.logged_in = True
def emailvalidator(email):
pattern = r'^[\w\.-]+@grcai\.com$'
if not re.match(pattern, email):
st.error('Email must be a grcai.com email!')
def passwordvalidator(password):
if len(password) < 8:
st.error('Password must be at least 8 characters long!')
elif not re.search("[a-z]", password):
st.error('Password must contain at least one lowercase letter!')
elif not re.search("[A-Z]", password):
st.error('Password must contain at least one uppercase letter!')
elif not re.search("[0-9]", password):
st.error('Password must contain at least one number!')
elif not re.search(r"[!@#$%^&*()_+\-=[\]{};':,.<>/?]", password):
st.error('Password must contain at least one special character!')
@st.dialog("Sign Up")
def signupForm():
with st.form(key="SignupForm"):
username = st.text_input(label = "Username", max_chars = 30)
email = st.text_input(label = "Email", placeholder="user@grcai.com")
if email:
emailvalidator(email)
company = st.text_input(label = "Company Name")
st.divider()
password = st.text_input(label= "Password", type = "password", placeholder = "Atleast 8 characters", help = "Must include letters, numbers or special characters or both")
if password:
passwordvalidator(password)
repeat_password = st.text_input(label="Repeat Password", type = "password")
margin, buttoncol = st.columns([0.92,0.08])
signupSubmit = st.form_submit_button(label = "SignUp", use_container_width=True)
if signupSubmit:
if email == "" or password == "" or repeat_password == "" or username == "":
st.error('All fields are required!')
elif password != repeat_password:
st.error('Passwords do not match!')
else:
db = firebaseDB()
db.new_user(username, email, password, company)
st.toast("User Registered Successfully!")
st.rerun()
def introBar7():
introBar = st.container(height=40,border = True)
with introBar:
blankdiv, loginbutton, signupbutton, marginright = st.columns([0.75,0.1,0.1,0.05],vertical_alignment="center")
"""
with popover1:
st.markdown('''
LinkButton1
''', unsafe_allow_html=True)
with popover2:
st.markdown('''
LinkButton2
''', unsafe_allow_html=True)
with popover3:
st.markdown('''
LinkButton3
''', unsafe_allow_html=True)
with popover4:
st.markdown('''
LinkButton4
''', unsafe_allow_html=True)
"""
with loginbutton:
loginClick = st.button(label=":material/login: Login", use_container_width=True)
if loginClick:
loginForm()
with signupbutton:
signupClick = st.button(label="SignUp",type="primary",use_container_width=True)
if signupClick:
signupForm()
st.markdown(introBar7Style ,unsafe_allow_html=True)