CosmoAI commited on
Commit
af16451
·
1 Parent(s): 37828da

Delete Auth.py

Browse files
Files changed (1) hide show
  1. Auth.py +0 -80
Auth.py DELETED
@@ -1,80 +0,0 @@
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:[email protected]/?retryWrites=true&w=majority"
12
-
13
- # Create a new client and connect to the server
14
- client = MongoClient(uri)
15
-
16
- # Send a ping to confirm a successful connection
17
- try:
18
- client.admin.command('ping')
19
- print("Pinged your deployment. You successfully connected to MongoDB!")
20
- except Exception as e:
21
- print(e)
22
-
23
-
24
- def loadfile():
25
- with open("database/users.json") as file:
26
- data = json.load(file)
27
- return data
28
-
29
- def savefile(data):
30
- with open("database/users.json", "w") as file:
31
- json.dump(data, file, indent=4)
32
-
33
-
34
-
35
- def login():
36
- st.write("Login")
37
- username = st.text_input("Username")
38
- password = st.text_input("Password", type="password")
39
- if st.button("Login"):
40
- data = loadfile()
41
- if username in data:
42
- if data[username]["password"] == password:
43
- st.success("Logged In as {}".format(username))
44
- st.session_state.user = username
45
- else:
46
- st.error("Wrong Password")
47
- else:
48
- st.error("User not found")
49
-
50
-
51
- def register():
52
- st.write("Register")
53
- username = st.text_input("Username")
54
- password = st.text_input("Password", type="password")
55
- if st.button("Register"):
56
- data = loadfile()
57
- if username in data:
58
- st.error("User already exists")
59
- else:
60
- data[username] = {}
61
- data[username]["password"] = password
62
- savefile(data)
63
- st.success("User created")
64
-
65
-
66
-
67
-
68
- def main():
69
- if 'user' not in st.session_state:
70
- st.session_state.user = None
71
-
72
- if st.session_state.user is None:
73
- with st.sidebar:
74
- selected = option_menu(None, ['Login', 'Register'])
75
- if selected == 'Login':
76
- login()
77
- elif selected == 'Register':
78
- register()
79
- else:
80
- dashboard()