yves.gugger 6b6ec01484 feat: Add missing features - Stripe payments, password reset, rate limiting, contact form, newsletter
Backend:
- Add Stripe API endpoints (checkout, portal, webhook) in subscription.py
- Add password reset (forgot-password, reset-password) in auth.py
- Add email verification endpoints
- Add rate limiting with slowapi
- Add contact form and newsletter API (contact.py)
- Add webhook endpoint for Stripe (webhooks.py)
- Add NewsletterSubscriber model
- Extend User model with password reset and email verification tokens
- Extend email_service with new templates (password reset, verification, contact, newsletter)
- Update env.example with all new environment variables

Frontend:
- Add /forgot-password page
- Add /reset-password page with token handling
- Add /verify-email page with auto-verification
- Add forgot password link to login page
- Connect contact form to API
- Add API methods for all new endpoints

Documentation:
- Update README with new API endpoints
- Update environment variables documentation
- Update pages overview
2025-12-08 14:37:42 +01:00

66 lines
2.4 KiB
Python

"""User model."""
from datetime import datetime
from typing import Optional, List
from sqlalchemy import String, Boolean, DateTime
from sqlalchemy.orm import Mapped, mapped_column, relationship
from app.database import Base
class User(Base):
"""User model for authentication and domain tracking."""
__tablename__ = "users"
id: Mapped[int] = mapped_column(primary_key=True, index=True)
email: Mapped[str] = mapped_column(String(255), unique=True, index=True, nullable=False)
hashed_password: Mapped[str] = mapped_column(String(255), nullable=False)
# Profile
name: Mapped[Optional[str]] = mapped_column(String(100), nullable=True)
# Stripe
stripe_customer_id: Mapped[Optional[str]] = mapped_column(String(255), nullable=True)
# Status
is_active: Mapped[bool] = mapped_column(Boolean, default=True)
is_verified: Mapped[bool] = mapped_column(Boolean, default=False)
# Password Reset
password_reset_token: Mapped[Optional[str]] = mapped_column(String(255), nullable=True)
password_reset_expires: Mapped[Optional[datetime]] = mapped_column(DateTime, nullable=True)
# Email Verification
email_verification_token: Mapped[Optional[str]] = mapped_column(String(255), nullable=True)
email_verification_expires: Mapped[Optional[datetime]] = mapped_column(DateTime, nullable=True)
# Timestamps
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)
updated_at: Mapped[datetime] = mapped_column(
DateTime, default=datetime.utcnow, onupdate=datetime.utcnow
)
last_login: Mapped[Optional[datetime]] = mapped_column(DateTime, nullable=True)
# Relationships
domains: Mapped[List["Domain"]] = relationship(
"Domain", back_populates="user", cascade="all, delete-orphan"
)
subscription: Mapped["Subscription"] = relationship(
"Subscription", back_populates="user", uselist=False, cascade="all, delete-orphan"
)
portfolio_domains: Mapped[List["PortfolioDomain"]] = relationship(
"PortfolioDomain", back_populates="user", cascade="all, delete-orphan"
)
def __repr__(self) -> str:
return f"<User {self.email}>"
# Property aliases for compatibility
@property
def password_hash(self) -> str:
return self.hashed_password
@password_hash.setter
def password_hash(self, value: str):
self.hashed_password = value