Spaces:
Running
Running
File size: 1,881 Bytes
8e64778 3ec7ca8 8e64778 50d41d0 8e64778 e55469f 8e64778 73f232b 8e64778 | 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 65 |
import asyncio
import sys
import os
# Add parent dir to path
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from sqlmodel import select
from app.core.database import async_session_maker
from app.models.user import User, UserRole
from app.models.tenant import Tenant
from app.core.security import get_password_hash
async def create_superuser():
email = "axeroni.s2@gmail.com"
password = "admin" # Default password
print(f"Creating superuser: {email}")
async with async_session_maker() as session:
# Check if user exists
statement = select(User).where(User.email == email)
result = await session.execute(statement)
user = result.first()
if user:
print(f"User {email} already exists.")
return
# Create Tenant
print("Creating default tenant...")
tenant = Tenant(
name="Admin Tenant",
business_name="MicroFunnel Admin",
subscription_plan="enterprise"
)
session.add(tenant)
await session.commit()
await session.refresh(tenant)
# Create User
print("Creating user...")
user = User(
email=email,
hashed_password=get_password_hash(password),
full_name="Super Admin",
tenant_id=tenant.id,
role=UserRole.OWNER,
is_active=True,
is_superuser=True,
is_verified=True
)
session.add(user)
await session.commit()
print(f"Superuser created successfully!")
print(f"Email: {email}")
print(f"Password: {password}")
if __name__ == "__main__":
if sys.platform == 'win32':
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
asyncio.run(create_superuser())
|