from __future__ import annotations from datetime import datetime, timezone from sqlalchemy import DateTime, ForeignKey, Integer, String from sqlalchemy.orm import Mapped, mapped_column from .base import Base class PasswordReset(Base): """An emailed link to set a new password for a local account (milestone 497). The link carries a one-time key; only its sha256 is stored, as for invites. It works for an hour, once; asking again replaces it.""" __tablename__ = "password_resets" id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True) user_id: Mapped[str] = mapped_column( String(36), ForeignKey("users.id", ondelete="CASCADE"), nullable=False, index=True) key_hash: Mapped[str] = mapped_column(String(64), unique=True, nullable=False) created_at: Mapped[datetime] = mapped_column( DateTime(timezone=True), nullable=False, default=lambda: datetime.now(timezone.utc)) expires_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), nullable=False) used_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True), nullable=True)