# Path: models.py
# class User(BaseModel, UserMixin):
#     """
#     User represents an user for the application.
# 
#     Attributes:
#         first_name (str): User's first name
#         last_name (str): User's last name
#         email (str): User's **valid** email
#         password (str): User's password
#         admin (bool): User's admin status. Defaults to ``False``
# 
#     .. NOTE::
#         Each User resource must have an unique `email` field, meaning
#         that there cannot be two user's registered with the same email.
# 
#         For this reason, when checking for user's existence, the server requires
#         either the `uuid` of the user or its `email`.
#     """
#     uuid = UUIDField(unique=True)
#     first_name = CharField()
#     last_name = CharField()
#     email = CharField(unique=True)
#     password = CharField()
#     admin = BooleanField(default=False)
#     _schema = UserSchema
# 
#     @staticmethod
#     def exists(email):
#         """
#         Check that an user exists by checking the email field.
# 
#         Args:
#             email (str): User's email to check
#         """
#         try:
#             User.get(User.email == email)
#         except User.DoesNotExist:
#             return False
#         return True
# 
#     @staticmethod
#     def hash_password(password):
#         """
#         Use passlib to get a crypted password.
# 
#         Args:
#             password (str): password to hash
# 
#         Returns:
#             str: hashed password
#         """
#         return pbkdf2_sha256.hash(password)
# 
#     def verify_password(self, password):
#         """
#         Verify a clear password against the stored hashed password of the user
#         using passlib.
# 
#         Args:
#             password (str): Password to verify against the hashed stored password
#         Returns:
#             bool: wether the given email matches the stored one
#         """
#         return pbkdf2_sha256.verify(password, self.password)
# 
#     def add_favorite(user, item):
#         """Link the favorite item to user."""
#         return Favorite.create(
#             uuid=uuid4(),
#             item=item,
#             user=user,
#         )
# 
#     def delete_favorite(self, obj):
#         obj.delete_instance()


from flask_login import login_required, LoginManager
from models import User
        from flask_login import current_user
    """
    Current user loading logic. If the user exists return it, otherwise None.

    Args:
        user_id (int): Peewee user id

    Returns:
        models.User: The requested user
    """
    try:
        return User.get(User.id == user_id)
    except User.DoesNotExist:
        return None


@login_manager.request_loader
def load_user_from_request(request):
    """
    User login validation logic. If the user exists with the given username
    and with the correct password then returns the user, otherwise None.

    Args:
        request (Request): The flask request object used in endpoint handlers

    Returns:
        models.User: The logged user, None if login fails
    """
    if not request.authorization:
        return None
    try:

# Path: models.py
# class User(BaseModel, UserMixin):
#     """
#     User represents an user for the application.
# 
#     Attributes:
#         first_name (str): User's first name
#         last_name (str): User's last name
#         email (str): User's **valid** email
#         password (str): User's password
#         admin (bool): User's admin status. Defaults to ``False``
# 
#     .. NOTE::
#         Each User resource must have an unique `email` field, meaning
#         that there cannot be two user's registered with the same email.
# 
#         For this reason, when checking for user's existence, the server requires
#         either the `uuid` of the user or its `email`.
#     """
#     uuid = UUIDField(unique=True)
#     first_name = CharField()
#     last_name = CharField()
#     email = CharField(unique=True)
#     password = CharField()
#     admin = BooleanField(default=False)
#     _schema = UserSchema
# 
#     @staticmethod
#     def exists(email):
#         """
#         Check that an user exists by checking the email field.
# 
#         Args:
#             email (str): User's email to check
#         """
#         try:
#             User.get(User.email == email)
#         except User.DoesNotExist:
#             return False
#         return True
# 
#     @staticmethod
#     def hash_password(password):
#         """
#         Use passlib to get a crypted password.
# 
#         Args:
#             password (str): password to hash
# 
#         Returns:
#             str: hashed password
#         """
#         return pbkdf2_sha256.hash(password)
# 
#     def verify_password(self, password):
#         """
#         Verify a clear password against the stored hashed password of the user
#         using passlib.
# 
#         Args:
#             password (str): Password to verify against the hashed stored password
#         Returns:
#             bool: wether the given email matches the stored one
#         """
#         return pbkdf2_sha256.verify(password, self.password)
# 
#     def add_favorite(user, item):
#         """Link the favorite item to user."""
#         return Favorite.create(
#             uuid=uuid4(),
#             item=item,
#             user=user,
#         )
# 
#     def delete_favorite(self, obj):
#         obj.delete_instance()


# Path: auth.py
from flask_login import login_required, LoginManager
from models import User
        from flask_login import current_user

    """
    Current user loading logic. If the user exists return it, otherwise None.

    Args:
        user_id (int): Peewee user id

    Returns:
        models.User: The requested user
    """
    try:
        return User.get(User.id == user_id)
    except User.DoesNotExist:
        return None


@login_manager.request_loader
def load_user_from_request(request):
    """
    User login validation logic. If the user exists with the given username
    and with the correct password then returns the user, otherwise None.

    Args:
        request (Request): The flask request object used in endpoint handlers

    Returns:
        models.User: The logged user, None if login fails
    """
    if not request.authorization:
        return None
    try:

        user = User.get(User.email == request.authorization['username'])