Spaces:
Runtime error
Runtime error
newcode
Browse files
app.py
CHANGED
@@ -3,7 +3,13 @@ import json
|
|
3 |
from streamlit_option_menu import option_menu
|
4 |
from pymongo import MongoClient
|
5 |
import os
|
|
|
6 |
|
|
|
|
|
|
|
|
|
|
|
7 |
uri = os.environ["MONGO_CONNECTION_STRING"]
|
8 |
|
9 |
client = MongoClient(uri, tlsCertificateKeyFile="database/cert.pem")
|
@@ -12,7 +18,7 @@ db = client["myapp"]
|
|
12 |
|
13 |
col = db["users"]
|
14 |
|
15 |
-
|
16 |
try:
|
17 |
client.admin.command('ping')
|
18 |
print("Connection Established Successfully!")
|
@@ -20,6 +26,7 @@ except Exception as e:
|
|
20 |
print(f"Not Connected: {e}")
|
21 |
|
22 |
|
|
|
23 |
def Signup():
|
24 |
username = st.text_input("Username")
|
25 |
password = st.text_input("Password", type="password")
|
@@ -42,20 +49,28 @@ def Login():
|
|
42 |
password = st.text_input("Password")
|
43 |
|
44 |
if st.button("Login"):
|
45 |
-
|
46 |
-
|
47 |
-
|
|
|
|
|
|
|
48 |
else:
|
49 |
st.error("Your username or password do not match")
|
50 |
|
51 |
-
def main():
|
52 |
-
with st.sidebar:
|
53 |
-
selected = option_menu("Menu", ["Login", "Signup"], icons = ["house", "person"])
|
54 |
-
if selected == "Login":
|
55 |
-
Login()
|
56 |
|
57 |
-
|
58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
|
60 |
main()
|
61 |
|
|
|
3 |
from streamlit_option_menu import option_menu
|
4 |
from pymongo import MongoClient
|
5 |
import os
|
6 |
+
from home import dashboard
|
7 |
|
8 |
+
if 'user' not in st.session_state:
|
9 |
+
st.session_state['user'] = "Guest"
|
10 |
+
|
11 |
+
|
12 |
+
# Connecting to MongoDB
|
13 |
uri = os.environ["MONGO_CONNECTION_STRING"]
|
14 |
|
15 |
client = MongoClient(uri, tlsCertificateKeyFile="database/cert.pem")
|
|
|
18 |
|
19 |
col = db["users"]
|
20 |
|
21 |
+
# Checking connectiong to database
|
22 |
try:
|
23 |
client.admin.command('ping')
|
24 |
print("Connection Established Successfully!")
|
|
|
26 |
print(f"Not Connected: {e}")
|
27 |
|
28 |
|
29 |
+
|
30 |
def Signup():
|
31 |
username = st.text_input("Username")
|
32 |
password = st.text_input("Password", type="password")
|
|
|
49 |
password = st.text_input("Password")
|
50 |
|
51 |
if st.button("Login"):
|
52 |
+
allusers = list(col.find())
|
53 |
+
for anyuser in allusers:
|
54 |
+
if username == anyuser["username"] and password == anyuser["password"]:
|
55 |
+
st.success("You are logged in")
|
56 |
+
st.session_state["username"] = "isuser"
|
57 |
+
st.experimental_rerun()
|
58 |
else:
|
59 |
st.error("Your username or password do not match")
|
60 |
|
|
|
|
|
|
|
|
|
|
|
61 |
|
62 |
+
|
63 |
+
def main():
|
64 |
+
if st.session_state["username"] == "Guest":
|
65 |
+
with st.sidebar:
|
66 |
+
selected = option_menu("Menu", ["Login", "Signup"], icons = ["house", "person"])
|
67 |
+
if selected == "Login":
|
68 |
+
Login()
|
69 |
+
|
70 |
+
elif selected == "Signup":
|
71 |
+
Signup()
|
72 |
+
elif st.session_state["username"] == "isuser":
|
73 |
+
dashboard()
|
74 |
|
75 |
main()
|
76 |
|
home.py
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from streamlit_option_menu import option_menu
|
3 |
+
|
4 |
+
|
5 |
+
def dashboard():
|
6 |
+
st.title("Welcome to the Dashboard")
|
7 |
+
|
8 |
+
selected = option_menu(None, ["Create Reminder", "View Reminders", "Logout"], icons=["plus", "eye", "power-off"])
|
9 |
+
|
10 |
+
if selected == "Create Reminder":
|
11 |
+
st.subheader("Create Reminder")
|
12 |
+
elif selected == "View Reminders":
|
13 |
+
st.subheader("View Reminders")
|
14 |
+
elif selected == "Logout":
|
15 |
+
st.session_state["user"] = "Guest"
|
16 |
+
st.experimental_rerun()
|