File size: 1,111 Bytes
a3f397d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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"