Spaces:
Runtime error
Runtime error
File size: 2,005 Bytes
d3f54c7 d25f219 103c644 8494cf3 6294752 103c644 8494cf3 103c644 457ad20 8494cf3 5c0ccf5 598eeb3 e71b7c1 c7a760b 8494cf3 f082504 d25f219 c7b911d d25f219 aaf87e0 d25f219 103c644 a5183c2 c7a760b d25f219 33fa8fe d25f219 86a0d10 8494cf3 e37b8ca 8494cf3 90b87e7 33fa8fe 8494cf3 e37b8ca 8494cf3 fbf7872 8494cf3 33fa8fe d25f219 33fa8fe d25f219 33fa8fe d3f54c7 d25f219 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
import streamlit as st
from streamlit_option_menu import option_menu
from pymongo import MongoClient
import os
from home import dashboard
if 'user' not in st.session_state:
st.session_state['user'] = "Guest"
# Connecting to MongoDB
uri = os.environ["MONGO_CONNECTION_STRING"]
client = MongoClient(uri, tlsCertificateKeyFile="database/cert.pem")
db = client["myapp"]
col = db["users"]
# Checking connectiong to database
try:
client.admin.command('ping')
print("Connection Established Successfully!")
except Exception as e:
print(f"Not Connected: {e}")
def Signup():
username = st.text_input("Username")
password = st.text_input("Password", type="password")
confpass = st.text_input("Confirm Password", type="password")
newuser = {
"username": username,"password": password
}
if st.button("Signup"):
if password == confpass:
col.insert_one({"username": username, "password": password})
st.write("You are Registered Sucessfully")
else:
"Password do not match"
def Login():
username = st.text_input("username")
password = st.text_input("Password")
if st.button("Login"):
allusers = list(col.find())
for anyuser in allusers:
if username == anyuser["username"] and password == anyuser["password"]:
st.success("You are logged in")
st.session_state["user"] = "isuser"
st.experimental_rerun()
else:
st.error("Your username or password do not match")
def main():
if st.session_state["user"] == "Guest":
with st.sidebar:
selected = option_menu("Menu", ["Login", "Signup"], icons = ["house", "person"])
if selected == "Login":
Login()
elif selected == "Signup":
Signup()
elif st.session_state["user"] == "isuser":
dashboard()
main()
|