Update app.py
Browse files
app.py
CHANGED
|
@@ -1,13 +1,73 @@
|
|
| 1 |
-
|
| 2 |
import streamlit as st
|
| 3 |
-
import
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
-
for percent_complete in range(100):
|
| 10 |
-
time.sleep(0.1)
|
| 11 |
-
my_bar.progress(percent_complete + 1, text=progress_text)
|
| 12 |
|
| 13 |
main()
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
from streamlit_option_menu import option_menu
|
| 3 |
+
import json
|
| 4 |
+
from Home import dashboard
|
| 5 |
+
import pymongo
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
from pymongo.mongo_client import MongoClient
|
| 10 |
+
|
| 11 |
+
uri = "mongodb+srv://new-userr:thispassword@cluster0.nfkbemi.mongodb.net/?retryWrites=true&w=majority"
|
| 12 |
+
|
| 13 |
+
# Create a new client and connect to the server
|
| 14 |
+
client = MongoClient(uri)
|
| 15 |
+
|
| 16 |
+
db = client["Cosmo"]
|
| 17 |
+
|
| 18 |
+
col = db["Users"]
|
| 19 |
+
|
| 20 |
+
# Send a ping to confirm a successful connection
|
| 21 |
+
try:
|
| 22 |
+
client.admin.command('ping')
|
| 23 |
+
print("Pinged your deployment. You successfully connected to MongoDB!")
|
| 24 |
+
except Exception as e:
|
| 25 |
+
print(e)
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def login():
|
| 31 |
+
st.write("Login")
|
| 32 |
+
username = st.text_input("Username")
|
| 33 |
+
password = st.text_input("Password", type="password")
|
| 34 |
+
if st.button("Login"):
|
| 35 |
+
if username in col.find():
|
| 36 |
+
if password in col.find():
|
| 37 |
+
st.session_state.userr = username
|
| 38 |
+
st.experimental_rerun()
|
| 39 |
+
else:
|
| 40 |
+
st.error("Incorrect password")
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def register():
|
| 44 |
+
st.write("Register")
|
| 45 |
+
username = st.text_input("Username")
|
| 46 |
+
password = st.text_input("Password", type="password")
|
| 47 |
+
data = {
|
| 48 |
+
"Username": username,
|
| 49 |
+
"Password": password
|
| 50 |
+
}
|
| 51 |
+
if st.button("Register"):
|
| 52 |
+
col.insert_one(data)
|
| 53 |
+
st.success("User created!")
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
|
| 57 |
|
| 58 |
+
def main():
|
| 59 |
+
if 'user' not in st.session_state:
|
| 60 |
+
st.session_state.user = None
|
| 61 |
+
|
| 62 |
+
if st.session_state.user is None:
|
| 63 |
+
with st.sidebar:
|
| 64 |
+
selected = option_menu(None, ['Login', 'Register'])
|
| 65 |
+
if selected == 'Login':
|
| 66 |
+
login()
|
| 67 |
+
elif selected == 'Register':
|
| 68 |
+
register()
|
| 69 |
+
else:
|
| 70 |
+
dashboard()
|
| 71 |
|
|
|
|
|
|
|
|
|
|
| 72 |
|
| 73 |
main()
|