File size: 2,278 Bytes
55dc7cf
6119fd6
 
 
3d4c371
 
 
6119fd6
 
 
 
dfeb40a
6119fd6
 
3d4c371
6119fd6
 
 
 
 
 
 
 
bb8a9ac
6119fd6
 
bb8a9ac
 
6119fd6
 
 
 
 
 
 
 
 
b6a7971
6119fd6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bb8a9ac
6119fd6
 
 
 
78fe09f
 
 
 
58fe94e
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
87
88
89

from pymongo.mongo_client import MongoClient
import streamlit as st
from streamlit_option_menu import option_menu
import certifi

ca = certifi.where()

st.set_page_config(page_title="Reminder App", page_icon=":bell:", layout="centered")


uri = st.secrets["MONGO_CONNECTION_STRING"]

# create a new client and connect to the server
client = MongoClient(uri, tlsCAFile=ca)

try:
    client.admin.command('ping')
    print ("Pinged your deployment.you succesfully connected to MongoDB !")
except Exception as e:
    print (e)


db = client['AllData']


col = db['Users']





def signupPage():
     st.title("signup")
     username = st.text_input("Username", key="svusername")
     password = st.text_input("Password", type="password", key="password")
     a= st.number_input("Age", min_value=18, max_value=100, step=1, key="age")
     p = st.number_input("Phone", min_value=91, max_value=9999999999, key="phone")
     m= st.text_input("Email", key="mail")  

    
     newdetails = {
            "username": username,
            "password": password,
            "age": a,
            "phone": p,
            "mail": m
     }
          
     
     if st.button("Signup"):
         if username in col.distinct("username"):
             st.error("Username already exists")
         else:
             col.insert_one(newdetails)
             st.success("Successfully registered! You may now Login with your credentials")

            
def loginPage():
     st.title("login")
     username = st.text_input("Username", key="lvusername")
     email = st.text_input("Email", key="svemail")
     password = st.text_input("Password", type="password", key="lvpassword")
     if st.button("Login"):
         if username in col.distinct("username"):
             if password in col.distinct("password"):
                 st.success("Logged in as {}".format(username))
                 st.balloons()  
             else:
                 st.error("Incorrect username or password")
         else:
             st.error("Incorrect username or password")



def main():

    with st.sidebar:
        selected = option_menu(None, ["Login", "SignUp"])

    if selected == "Login":
        loginPage()
    elif selected == "SignUp":
        signupPage()


if __name__ == "__main__":
    main()