import pymongo
from conn_mongodb import *

# client = pymongo.MongoClient("mongodb://admin:readgazer_2022@81.69.91.171:27017/test")
# db = client["ReaderGazer"]  # 或者用db = client.cnnStories

# userInfo_col = db.userInfo

# userInfo_col.insert_one({"email": "admin", "username": "admin", "password": "admin", "status": "admin"})


def signup(email, username, password):
    res = userInfo_col.find_one({"email": email})
    if (res == None):
        query = {"email": email, "username": username, "password": password, "status": "stu"}
        print(userInfo_col.insert_one(query))
        return email
    else:
        return "NO"


def login(email, password):
    res = userInfo_col.find_one({"email": email})
    if (res == None):
        return "signup"
    elif (password == res["password"]):
        if (res["status"] == "admin"):
            return "admin"
        else:
            return email
    else:
        return "wrong"

# t=login("1", "1")
# print(userInfo_col.find()[0])

# t=userInfo_col.find()[0]
# print(t)