feat(phase-1): Complete foundation setup

- 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>
This commit is contained in:
2026-01-28 01:30:15 +00:00
parent 049d2133f9
commit 541a8484a7
14 changed files with 1092 additions and 18 deletions

View File

@@ -4,6 +4,7 @@ Modelos de base de datos SQLAlchemy.
from app.core.database import Base
from app.models.user import User
from app.models.product import Product
from app.models.service import Service
from app.models.tip_template import TipTemplate
@@ -14,6 +15,7 @@ from app.models.interaction import Interaction
__all__ = [
"Base",
"User",
"Product",
"Service",
"TipTemplate",

49
app/models/user.py Normal file
View File

@@ -0,0 +1,49 @@
"""
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
}