Spaces:
Sleeping
Sleeping
| from pymongo import MongoClient | |
| import os | |
| uri = f"mongodb+srv://{os.getenv('mongo_secret')}@void-uep.guig8vk.mongodb.net/?retryWrites=true&w=majority" | |
| client = MongoClient(uri) | |
| 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" | |