"""User account model (JWT-based authentication, see ``core.auth``).""" from __future__ import annotations from datetime import datetime, timezone from sqlalchemy import Boolean, DateTime, String from sqlalchemy.orm import Mapped, mapped_column from models.base import Base def _utcnow() -> datetime: return datetime.now(timezone.utc) class User(Base): """A registered newzy account. ``password_hash`` stores ``"$"`` (see ``core.auth.hash_password``) — never the plaintext password. """ __tablename__ = "users" id: Mapped[int] = mapped_column(primary_key=True) username: Mapped[str] = mapped_column(String(60), unique=True, index=True) password_hash: Mapped[str] = mapped_column(String(128)) #: Grants access to the admin area (``/api/v1/admin/*``). Never set by #: the registration endpoint; promote users via ``seed_admin.py``. is_admin: Mapped[bool] = mapped_column(Boolean, default=False, nullable=False) created_at: Mapped[datetime] = mapped_column( DateTime(timezone=True), default=_utcnow, nullable=False ) def __repr__(self) -> str: # pragma: no cover return f""