|
import streamlit as st |
|
from streamlit_option_menu import option_menu |
|
import json |
|
from Home import dashboard |
|
import pymongo |
|
from python-dotenv import dotenv |
|
|
|
load_dotenv() |
|
|
|
from pymongo.mongo_client import MongoClient |
|
|
|
uri = "MONGO_CONNECTION_STRING" |
|
|
|
|
|
client = MongoClient(uri) |
|
|
|
db = client["Cosmo"] |
|
|
|
col = db["Users"] |
|
|
|
|
|
try: |
|
client.admin.command('ping') |
|
print("Pinged your deployment. You successfully connected to MongoDB!") |
|
except Exception as e: |
|
print(e) |
|
|
|
|
|
|
|
|
|
def login(): |
|
st.write("Login") |
|
username = st.text_input("Username") |
|
password = st.text_input("Password", type="password") |
|
if st.button("Login"): |
|
if username in col.find(): |
|
if password in col.find(): |
|
st.session_state.userr = username |
|
st.experimental_rerun() |
|
else: |
|
st.error("Incorrect password") |
|
|
|
|
|
def register(): |
|
st.write("Register") |
|
username = st.text_input("Username") |
|
password = st.text_input("Password", type="password") |
|
data = { |
|
"Username": username, |
|
"Password": password |
|
} |
|
if st.button("Register"): |
|
col.insert_one(data) |
|
st.success("User created!") |
|
|
|
|
|
|
|
|
|
def main(): |
|
if 'user' not in st.session_state: |
|
st.session_state.user = None |
|
|
|
if st.session_state.user is None: |
|
with st.sidebar: |
|
selected = option_menu(None, ['Login', 'Register']) |
|
if selected == 'Login': |
|
login() |
|
elif selected == 'Register': |
|
register() |
|
else: |
|
dashboard() |
|
|
|
|
|
main() |