from datetime import datetime import streamlit as st import streamlit_authenticator as stauth import yaml from yaml.loader import SafeLoader from utils.frontend.helper import * st.set_page_config(page_title="SAAS Template App", page_icon="🧊", layout="wide") with open("config.yaml") as file: config = yaml.load(file, Loader=SafeLoader) authenticator = stauth.Authenticate( config["credentials"], config["cookie"]["name"], config["cookie"]["key"], config["cookie"]["expiry_days"], config["preauthorized"], ) # Credit: Time def current_year(): now = datetime.now() return now.year with st.sidebar: if not st.session_state["authentication_status"]: st.markdown( """ # Welcome to **Llama3 Full Stack** 🎶🤖 This is a full-stack Software-as-a-Service template for a Llama3 backed chatbot with login authentication using Streamlit. 🚀 ### 🖱️Press "R" on your keyboard⌨️ to rerun the app for faster loading 🔄. ### 🔒Sample login info - User: "jsmith" | Password: "abc" """ ) # Default video st.write( "👋 Welcome to use the sample info to log in!" ) with st.expander("Login 🔒", expanded=True): authenticator.login("Login", "main") if st.session_state["authentication_status"]: authenticator.logout("Logout", "main", key="unique_key_login") st.write(f'Welcome *{st.session_state["name"]}*') st.title( "You logged in! You can choose a session in the bottom of the sidebar and view content." ) elif st.session_state["authentication_status"] is False: st.error("Username/password is incorrect") elif st.session_state["authentication_status"] is None: st.warning("Please enter your username and password") with st.expander("Reset password 😕"): if st.session_state["authentication_status"]: try: if authenticator.reset_password( st.session_state["username"], "Reset password" ): st.success("Password modified successfully") except Exception as e: st.error(e) with st.expander("Forgot password 😕"): try: ( username_of_forgotten_password, email_of_forgotten_password, new_random_password, ) = authenticator.forgot_password("Forgot password") if username_of_forgotten_password: st.success("New password to be sent securely") # Random password should be transferred to user securely else: st.error("Username not found") except Exception as e: st.error(e) with st.expander("Update user 😋"): if st.session_state["authentication_status"]: try: if authenticator.update_user_details( st.session_state["username"], "Update user details" ): st.success("Entries updated successfully") except Exception as e: st.error(e) with st.expander("Register user 😋"): try: # payment_key = st.text_input("Enter Payment Key:") if authenticator.register_user("Register user", preauthorization=False): # if register_user(payment_key): st.success("User registered successfully") except Exception as e: st.error(e) with open("config.yaml", "w") as file: yaml.dump(config, file, default_flow_style=False) with st.expander("Donation💲"): stripe_payment_link = "https://buy.stripe.com/cN2bLGa0faMp5u8fYZ" st.markdown( f""" Want to support me? 😄 Done here using this [link]({stripe_payment_link}). """ ) # Credit: current_year = current_year() # This will print the current year st.markdown( f"""