This commit is contained in:
rob
2025-09-11 10:15:27 +01:00
commit c1011af06a
53 changed files with 5953 additions and 0 deletions
+34
View File
@@ -0,0 +1,34 @@
"""Auth."""
from flask_httpauth import HTTPBasicAuth, HTTPTokenAuth
from models.user import User
from errors import error_response
basic_auth = HTTPBasicAuth()
token_auth = HTTPTokenAuth()
@basic_auth.verify_password
def verify_password(email, password):
"""Verify password."""
user = User.query.filter_by(email=email).first()
if user and user.check_password(password):
return user
@basic_auth.error_handler
def basic_auth_error(status):
"""Basic auth error."""
return error_response(status)
@token_auth.verify_token
def verify_token(token):
"""Verify token."""
return User.check_token(token) if token else None
@token_auth.error_handler
def token_auth_error(status):
"""Token auth error."""
return error_response(status)