transcription-cost-usage-re.../backend/app/db/models.py

20 lines
711 B
Python
Raw Normal View History

2025-06-09 11:13:05 +00:00
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)