Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added authentication for the dashboard! #13

Merged
merged 3 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 36 additions & 28 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,44 @@
import logging
import os
from datetime import datetime

import pandas as pd
import streamlit as st
import yaml
from streamlit_authenticator import Authenticate
from dotenv import load_dotenv
from streamlit_authenticator import Authenticate, Hasher
from utils.mongo import MongoSingleton
from utils.process_guild_data import process_guild_data
from yaml.loader import SafeLoader

logging.basicConfig(level=logging.INFO)
load_dotenv()
st.subheader("TogetherCrew's Amin Panel")
# Get environment variables
names = os.getenv("NAMES").split(",")
usernames = os.getenv("USERNAMES").split(",")
passwords = os.getenv("PASSWORDS").split(",")
secret_key = os.getenv("SECRET_KEY")
hashed_passwords = Hasher(passwords).generate()

# Set up the authenticator
authenticator = Authenticate(
credentials={
"usernames": {
usernames[i]: {"name": names[i], "password": hashed_passwords[i]}
for i in range(len(usernames))
}
},
cookie_name="auth_cookie",
key=secret_key,
cookie_expiry_days=30,
)

# Login function
name, authentication_status, username = authenticator.login()

if authentication_status:
authenticator.logout("Logout", "main")
st.write(f"Welcome *{name}*")

def load_guilds_latest_date_df():
client = MongoSingleton.get_instance().client

cursor = client["Core"]["platforms"].find({"name": "discord"})
Expand All @@ -35,27 +63,7 @@ def load_guilds_latest_date_df():
df = pd.DataFrame(guilds_data)
dataframe_widget.dataframe(df)


logging.basicConfig(level=logging.INFO)
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 is False:
# st.error("Username/password is incorrect")
# elif authentication_status is None:
# st.warning("Please enter your username and password")
elif authentication_status is False:
st.error("Username/password is incorrect")
elif authentication_status is None:
st.warning("Please enter your username and password")
4 changes: 4 additions & 0 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ services:
- NEO4J_AUTH=neo4j/password
- NEO4J_PLUGINS=["apoc", "graph-data-science"]
- NEO4J_dbms_security_procedures_unrestricted=apoc.*,gds.*
- USERNAMES=johndoe,janesmith
- NAMES=John Doe,Jane Smith
- PASSWORDS=password1,password2
- SECRET_KEY=my_secret_key
amindadgar marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 4 additions & 0 deletions docker-compose.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ services:
- NEO4J_USER=neo4j
- NEO4J_PASSWORD=password
- NEO4J_DB=neo4j
- USERNAMES=johndoe,janesmith
- NAMES=John Doe,Jane Smith
- PASSWORDS=password1,password2
amindadgar marked this conversation as resolved.
Show resolved Hide resolved
amindadgar marked this conversation as resolved.
Show resolved Hide resolved
- SECRET_KEY=my_secret_key
amindadgar marked this conversation as resolved.
Show resolved Hide resolved
volumes:
- ./coverage:/project/coverage
depends_on:
Expand Down
Loading