50 lines
1.8 KiB
Python
50 lines
1.8 KiB
Python
"""
|
|
Script para resetear contraseñas de todos los usuarios a valores conocidos.
|
|
Ejecutar con: python -m scripts.reset_passwords (desde /app en el contenedor)
|
|
"""
|
|
import asyncio
|
|
from sqlalchemy import select, update
|
|
from app.core.database import AsyncSessionLocal
|
|
from app.core.security import security
|
|
from app.models.user import User
|
|
|
|
# Mapa email -> nueva contraseña
|
|
PASSWORD_MAP = {
|
|
"admin@aduanasoft.com": "admin123",
|
|
"admin@test.com": "admin123",
|
|
"manager@aduanasoft.com": "manager123",
|
|
"agente@aduanasoft.com": "agente123",
|
|
"auditor1@test.com": "auditor123",
|
|
"admin-cliente@empresa-demo.com": "clienteadmin123",
|
|
"cliente@empresa-demo.com": "cliente123",
|
|
"test_user@aduanasoft.com": "test123",
|
|
}
|
|
|
|
async def reset_all_passwords():
|
|
async with AsyncSessionLocal() as db:
|
|
result = await db.execute(select(User))
|
|
users = result.scalars().all()
|
|
|
|
updated = 0
|
|
skipped = 0
|
|
for user in users:
|
|
if user.email in PASSWORD_MAP:
|
|
plain = PASSWORD_MAP[user.email]
|
|
user.password_hash = security.hash_password(plain)
|
|
user.email_verified = True
|
|
user.is_active = True
|
|
updated += 1
|
|
print(f" ✅ {user.email} → {plain}")
|
|
else:
|
|
skipped += 1
|
|
print(f" ⚠️ {user.email} (sin contraseña definida, se omite)")
|
|
|
|
await db.commit()
|
|
print(f"\nResumen: {updated} actualizados, {skipped} omitidos")
|
|
print("\n📋 Credenciales listas:")
|
|
for email, pwd in PASSWORD_MAP.items():
|
|
print(f" {email} / {pwd}")
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(reset_all_passwords())
|