#!/usr/bin/env python """Create demo admin user for testing.""" import sys from pathlib import Path # Add backend to path sys.path.insert(0, str(Path(__file__).parent.parent)) import bcrypt from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker from core.models.user import User, UserRole def hash_password(password: str) -> str: """Hash password using bcrypt.""" return bcrypt.hashpw(password.encode("utf-8"), bcrypt.gensalt()).decode("utf-8") def create_admin_user(): """Create demo admin user.""" database_url = "sqlite:///./fraud_detection.db" engine = create_engine(database_url) session_local = sessionmaker(bind=engine) db = session_local() try: # Check if user already exists existing_user = db.query(User).filter(User.email == "admin@zenith.com").first() if existing_user: print("✅ Admin user already exists!") return # Create admin user hashed_password = hash_password("password123") admin_user = User( username="admin", email="admin@zenith.com", full_name="Admin User", password_hash=hashed_password, role=UserRole.ADMIN, is_active=True, ) db.add(admin_user) db.commit() print("✅ Admin user created successfully!") print(" Email: admin@zenith.com") print(" Password: password123") except Exception as e: print(f"❌ Error creating user: {e}") db.rollback() finally: db.close() if __name__ == "__main__": create_admin_user()