diff --git a/.gitignore b/.gitignore index d6fcfe5..dc24ab3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ .env __pycache__ environment/* +config.yaml +main.ipynb diff --git a/app.py b/app.py index 868b654..a4824e1 100644 --- a/app.py +++ b/app.py @@ -5,9 +5,11 @@ import streamlit as st from utils.mongo import MongoSingleton from utils.process_guild_data import process_guild_data +from streamlit_authenticator import Authenticate +import yaml +from yaml.loader import SafeLoader -# @st.cache_data def load_guilds_latest_date_df(): client = MongoSingleton.get_instance().client @@ -35,8 +37,25 @@ def load_guilds_latest_date_df(): logging.basicConfig(level=logging.INFO) - -st.subheader("MongoDB data Analytics") -load_guilds_latest_date_df() -# df = process_df(df) -# st.dataframe(df, use_container_width=True, hide_index=True) +st.subheader("TogetherCrew's Amin Panel") +with open("config.yaml") as file: + config = yaml.load(file, Loader=SafeLoader) + +authenticator = Authenticate( + config["credentials"], + config["cookie"]["name"], + config["cookie"]["key"], + config["cookie"]["expiry_days"], + config["preauthorized"], +) +name, authentication_status, username = authenticator.login() + +if authentication_status: + authenticator.logout("Logout", "main") + st.write(f"Welcome *{name}*") + # st.title('Some content') + load_guilds_latest_date_df() +elif authentication_status == False: + st.error("Username/password is incorrect") +elif authentication_status == None: + st.warning("Please enter your username and password") diff --git a/config.yaml.example b/config.yaml.example new file mode 100644 index 0000000..2edf3a3 --- /dev/null +++ b/config.yaml.example @@ -0,0 +1,13 @@ +credentials: + usernames: + jsmith: + email: jsmith@gmail.com + name: John Smith + password: abc # To be replaced with hashed password +cookie: + expiry_days: 30 + key: random_signature_key # Must be string + name: random_cookie_name +preauthorized: + emails: + - melsby@gmail.com \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index f6e9bd6..6235ba5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ streamlit +streamlit-authenticator numpy pandas matplotlib