ImagiGen_v2 / mongo_db.py
Tejasva-Maurya's picture
Create mongo_db.py
a3f397d verified
raw
history blame
1.11 kB
from pymongo import MongoClient
client = MongoClient(
{os.getenv('mongo_secret')}
)
db = client["ImagiGen"]
users_collection = db["users"]
def register(email_id, password):
if users_collection.find_one({"email": email_id}):
return "Email ID already Registered"
# Insert new user into the collection
users_collection.insert_one({"email": email_id, "password": password})
return "Registration successful"
def login(email_id, password):
user = users_collection.find_one({"email": email_id, "password": password})
if user:
return "Login successful"
else:
return "Invalid credentials"
def google_register(username, email):
if users_collection.find_one({"email": email}):
return "email ID already Registered"
# Insert new user into the collection
users_collection.insert_one({"username": username, "email": email})
return "Registration successful"
def google_login(email_id):
user = users_collection.find_one({"email": email_id})
if user:
return "Login successful"
else:
return "Invalid credentials"