Spaces:
Running
Running
Download backend/scripts/create_superuser.py from axeronis/microfunnel-api: direct link, hf CLI and curl.
- Browser
- Download file 1.88 kB
-
https://huggingface.co/spaces/axeronis/microfunnel-api/resolve/2c5de26c1a17aff6794de780c66253fd5bb2f22b/backend/scripts/create_superuser.py
- Command line
-
hf download hf://spaces/axeronis/microfunnel-api@2c5de26c1a17aff6794de780c66253fd5bb2f22b/backend/scripts/create_superuser.py
-
curl -L -o create_superuser.py https://huggingface.co/spaces/axeronis/microfunnel-api/resolve/2c5de26c1a17aff6794de780c66253fd5bb2f22b/backend/scripts/create_superuser.py
1.88 kB
| 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()) | |