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 1 commit
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
65 changes: 37 additions & 28 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,45 @@
import logging
from datetime import datetime

import os
from dotenv import load_dotenv
import pandas as pd
import streamlit as st
import yaml
from streamlit_authenticator import Authenticate
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


def load_guilds_latest_date_df():
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}*")

client = MongoSingleton.get_instance().client

cursor = client["Core"]["platforms"].find({"name": "discord"})
Expand All @@ -35,27 +64,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
Loading