from flask_bcrypt import generate_password_hash, check_password_hash from flask import current_app from pymongo import MongoClient class UserModel: def __init__(self): client = current_app.mongo_client self.collection = client["billing-api"]["users"] def create_user(self, email, password): hashed = generate_password_hash(password).decode('utf-8') user = {"email": email, "password": hashed} return self.collection.insert_one(user) def find_by_email(self, email): return self.collection.find_one({"email": email}) def verify_password(self, hashed_password, plain_password): return check_password_hash(hashed_password, plain_password)