import sys import os import json # Asegurar que el directorio raíz esté en PYTHONPATH sys.path.append(os.path.dirname(os.path.abspath(__file__))) from app.core.security import SecurityUtils from app.core.config import settings from app.models.user import User from app.models.tenant import Tenant from app.core.database import AsyncSessionLocal from sqlalchemy.future import select import asyncio # Generar un token predeterminado para el usuario admin def generate_default_token(): async def async_task(): async with AsyncSessionLocal() as db: result = await db.execute(select(User).filter(User.email == "admin@aduanasoft.com")) user = result.scalar_one_or_none() if user: print(f"User found: {user.email}") token = SecurityUtils.create_access_token({"sub": str(user.id), "email": user.email}) print(f"Generated token: {token}") # Validate the token payload = SecurityUtils.verify_token(token) if payload: print("Token is valid. Payload:") print(json.dumps(payload, indent=4)) else: print("Token validation failed.") else: print("User not found. Token not generated.") asyncio.run(async_task()) generate_default_token() print("Token generation process completed.")