- Add User model and authentication system with JWT cookies - Implement login/logout routes and protected dashboard - Add Alembic database migration configuration - Add create_admin.py script for initial user setup - Make ContentGenerator and ImageGenerator lazy-initialized - Add comprehensive API keys setup documentation - Fix startup errors when services unavailable Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
50 lines
1.5 KiB
Python
50 lines
1.5 KiB
Python
"""
|
|
Modelo de Usuario para autenticación del dashboard.
|
|
"""
|
|
|
|
from datetime import datetime
|
|
from sqlalchemy import Column, Integer, String, Boolean, DateTime
|
|
|
|
from app.core.database import Base
|
|
|
|
|
|
class User(Base):
|
|
"""Modelo para usuarios del dashboard."""
|
|
|
|
__tablename__ = "users"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
|
|
# Credenciales
|
|
username = Column(String(50), unique=True, nullable=False, index=True)
|
|
email = Column(String(255), unique=True, nullable=False, index=True)
|
|
hashed_password = Column(String(255), nullable=False)
|
|
|
|
# Información
|
|
full_name = Column(String(255), nullable=True)
|
|
|
|
# Estado
|
|
is_active = Column(Boolean, default=True)
|
|
is_superuser = Column(Boolean, default=False)
|
|
|
|
# Timestamps
|
|
last_login = Column(DateTime, nullable=True)
|
|
created_at = Column(DateTime, default=datetime.utcnow)
|
|
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
|
|
|
def __repr__(self):
|
|
return f"<User {self.username}>"
|
|
|
|
def to_dict(self):
|
|
"""Convertir a diccionario (sin password)."""
|
|
return {
|
|
"id": self.id,
|
|
"username": self.username,
|
|
"email": self.email,
|
|
"full_name": self.full_name,
|
|
"is_active": self.is_active,
|
|
"is_superuser": self.is_superuser,
|
|
"last_login": self.last_login.isoformat() if self.last_login else None,
|
|
"created_at": self.created_at.isoformat() if self.created_at else None
|
|
}
|