48 lines
1.2 KiB
Python
48 lines
1.2 KiB
Python
import pymongo
|
|
import random
|
|
from werkzeug.security import *
|
|
|
|
client = pymongo.MongoClient("mongodb://192.168.86.221:27017/")
|
|
db = client.VE
|
|
|
|
def create_account(name, email, password):
|
|
coll = db.accounts
|
|
|
|
user = coll.find_one({"email": email})
|
|
if user is not None:
|
|
print("An account using that email has already been created..")
|
|
return
|
|
|
|
code = random.randint(000000, 999999)
|
|
|
|
coll.insert_one({"_id": code, "email": email, "password": generate_password_hash(password, "scrypt"), "name": name})
|
|
|
|
return code
|
|
|
|
def find_account(code = None, email = None, password = None):
|
|
coll = db.accounts
|
|
if email is not None and password is not None:
|
|
user = coll.find_one({"email": email})
|
|
user_encrypt_pass = user["password"]
|
|
|
|
if user is None:
|
|
print("An account with that email could not be found..")
|
|
return None
|
|
|
|
is_password_correct = check_password_hash(user_encrypt_pass, password)
|
|
|
|
if is_password_correct is False:
|
|
print("The password entered is incorrect..")
|
|
return None
|
|
|
|
return user['_id']
|
|
|
|
user = coll.find_one({"_id": code})
|
|
|
|
if user is None:
|
|
print("That account could not be found..")
|
|
return None
|
|
|
|
return code
|
|
|