Skip to content

Building 70 Projects ranging from beginner to advanced so anyone can — learn from, build upon, use as a reference, or even copy directly. Owned by my cybersecurity company 👇

962 B
Raw Blame
"""
ⒸAngelaMos | 2025
User model for authentication and user management
"""

from sqlalchemy import (
    Boolean,
    Column,
    String,
)

from config import settings
from .Base import BaseModel


class User(BaseModel):
    """
    Stores authentication credentials and user information
    """

    __tablename__ = "users"

    email = Column(
        String(settings.EMAIL_MAX_LENGTH),
        unique = True,
        nullable = False,
        index = True,
    )
    hashed_password = Column(String, nullable = False)
    is_active = Column(Boolean, default = True, nullable = False)

    def __repr__(self) -> str:
        """
        String representation of User
        """
        return f"<User(id={self.id}, email={self.email})>"

    @property
    def is_authenticated(self) -> bool:
        """
        Check if user is active and authenticated

        Returns:
            bool: True if user is active
        """
        return self.is_active