- User model with email/hashed_password/is_admin/notification_prefs - JWT auth: POST /api/auth/register, /login, /me - First registered user auto-promoted to admin - Migration 0005: users table + user_id FK on follows (clears global follows) - Follows, dashboard, settings, admin endpoints all require authentication - Admin endpoints (settings writes, celery triggers) require is_admin - Frontend: login/register pages, Zustand auth store (localStorage persist) - AuthGuard component gates all app routes, shows app shell only when authed - Sidebar shows user email + logout; Admin nav link visible to admins only - Admin panel (/settings): user list with delete + promote/demote, LLM config, data source settings, and manual celery controls Authored-By: Jack Levy
20 lines
749 B
Python
20 lines
749 B
Python
from sqlalchemy import Boolean, Column, DateTime, Integer, String
|
|
from sqlalchemy.dialects.postgresql import JSONB
|
|
from sqlalchemy.orm import relationship
|
|
from sqlalchemy.sql import func
|
|
|
|
from app.database import Base
|
|
|
|
|
|
class User(Base):
|
|
__tablename__ = "users"
|
|
|
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
|
email = Column(String, unique=True, nullable=False, index=True)
|
|
hashed_password = Column(String, nullable=False)
|
|
is_admin = Column(Boolean, nullable=False, default=False)
|
|
notification_prefs = Column(JSONB, nullable=False, default=dict)
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
|
|
follows = relationship("Follow", back_populates="user", cascade="all, delete-orphan")
|