Spaces:
Running
Running
Create mongo_db.py
Browse files- mongo_db.py +39 -0
mongo_db.py
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from pymongo import MongoClient
|
2 |
+
|
3 |
+
client = MongoClient(
|
4 |
+
{os.getenv('mongo_secret')}
|
5 |
+
)
|
6 |
+
db = client["ImagiGen"]
|
7 |
+
users_collection = db["users"]
|
8 |
+
|
9 |
+
|
10 |
+
def register(email_id, password):
|
11 |
+
if users_collection.find_one({"email": email_id}):
|
12 |
+
return "Email ID already Registered"
|
13 |
+
# Insert new user into the collection
|
14 |
+
users_collection.insert_one({"email": email_id, "password": password})
|
15 |
+
return "Registration successful"
|
16 |
+
|
17 |
+
|
18 |
+
def login(email_id, password):
|
19 |
+
user = users_collection.find_one({"email": email_id, "password": password})
|
20 |
+
if user:
|
21 |
+
return "Login successful"
|
22 |
+
else:
|
23 |
+
return "Invalid credentials"
|
24 |
+
|
25 |
+
|
26 |
+
def google_register(username, email):
|
27 |
+
if users_collection.find_one({"email": email}):
|
28 |
+
return "email ID already Registered"
|
29 |
+
# Insert new user into the collection
|
30 |
+
users_collection.insert_one({"username": username, "email": email})
|
31 |
+
return "Registration successful"
|
32 |
+
|
33 |
+
|
34 |
+
def google_login(email_id):
|
35 |
+
user = users_collection.find_one({"email": email_id})
|
36 |
+
if user:
|
37 |
+
return "Login successful"
|
38 |
+
else:
|
39 |
+
return "Invalid credentials"
|