Admin Panel: - User Detail Modal with full profile info - Bulk tier upgrade for multiple users - User export to CSV - Price Alerts overview tab - Domain Health Check trigger - Email Test functionality - Scheduler Status with job info and last runs - Activity Log for admin actions - Blog management tab with CRUD Blog System: - BlogPost model with full content management - Public API: list, featured, categories, single post - Admin API: create, update, delete, publish/unpublish - Frontend blog listing page with categories - Frontend blog detail page with styling - View count tracking OAuth: - Google OAuth integration - GitHub OAuth integration - OAuth callback handling - Provider selection on login/register Other improvements: - Domain checker with check_all_domains function - Admin activity logging - Breadcrumbs component - Toast notification component - Various UI/UX improvements
72 lines
2.8 KiB
Python
72 lines
2.8 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)
|
|
is_admin: 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)
|
|
|
|
# OAuth
|
|
oauth_provider: Mapped[Optional[str]] = mapped_column(String(50), nullable=True) # 'google', 'github'
|
|
oauth_id: Mapped[Optional[str]] = mapped_column(String(255), nullable=True)
|
|
oauth_avatar: Mapped[Optional[str]] = mapped_column(String(500), 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
|