Spaces:
Paused
Paused
File size: 1,641 Bytes
d29a5a0 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | #!/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()
|