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:
90
scripts/create_admin.py
Normal file
90
scripts/create_admin.py
Normal file
@@ -0,0 +1,90 @@
|
||||
"""
|
||||
Script para crear el usuario administrador inicial.
|
||||
"""
|
||||
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
# Agregar el directorio raíz al path
|
||||
sys.path.insert(0, str(Path(__file__).parent.parent))
|
||||
|
||||
from app.core.database import SessionLocal
|
||||
from app.core.security import get_password_hash
|
||||
from app.models.user import User
|
||||
|
||||
|
||||
def create_admin(username: str, email: str, password: str, full_name: str = None):
|
||||
"""Crear usuario administrador."""
|
||||
db = SessionLocal()
|
||||
|
||||
try:
|
||||
# Verificar si ya existe
|
||||
existing = db.query(User).filter(
|
||||
(User.username == username) | (User.email == email)
|
||||
).first()
|
||||
|
||||
if existing:
|
||||
print(f"⚠️ Usuario '{username}' o email '{email}' ya existe")
|
||||
return False
|
||||
|
||||
# Crear usuario
|
||||
user = User(
|
||||
username=username,
|
||||
email=email,
|
||||
hashed_password=get_password_hash(password),
|
||||
full_name=full_name or username,
|
||||
is_active=True,
|
||||
is_superuser=True
|
||||
)
|
||||
|
||||
db.add(user)
|
||||
db.commit()
|
||||
|
||||
print(f"✅ Usuario administrador creado: {username}")
|
||||
print(f" Email: {email}")
|
||||
print(f" Password: {'*' * len(password)}")
|
||||
return True
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ Error: {e}")
|
||||
db.rollback()
|
||||
return False
|
||||
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
|
||||
def main():
|
||||
"""Main entry point."""
|
||||
import argparse
|
||||
|
||||
parser = argparse.ArgumentParser(description="Crear usuario administrador")
|
||||
parser.add_argument("--username", "-u", default="admin", help="Nombre de usuario")
|
||||
parser.add_argument("--email", "-e", required=True, help="Email del usuario")
|
||||
parser.add_argument("--password", "-p", required=True, help="Contraseña")
|
||||
parser.add_argument("--name", "-n", help="Nombre completo")
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
create_admin(
|
||||
username=args.username,
|
||||
email=args.email,
|
||||
password=args.password,
|
||||
full_name=args.name
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Si no hay argumentos, usar valores por defecto para desarrollo
|
||||
if len(sys.argv) == 1:
|
||||
print("Uso: python create_admin.py -e email@example.com -p password")
|
||||
print()
|
||||
print("Creando usuario admin por defecto para desarrollo...")
|
||||
create_admin(
|
||||
username="admin",
|
||||
email="admin@consultoria-as.com",
|
||||
password="admin123",
|
||||
full_name="Administrador"
|
||||
)
|
||||
else:
|
||||
main()
|
||||
Reference in New Issue
Block a user