Spaces:
Running
Running
Download backend/check_admin_user.py from axeronis/microfunnel-api: direct link, hf CLI and curl.
- Browser
- Download file 1.62 kB
-
https://huggingface.co/spaces/axeronis/microfunnel-api/resolve/main/backend/check_admin_user.py
- Command line
-
hf download hf://spaces/axeronis/microfunnel-api/backend/check_admin_user.py
-
curl -L -o check_admin_user.py https://huggingface.co/spaces/axeronis/microfunnel-api/resolve/main/backend/check_admin_user.py
1.62 kB
| import asyncio | |
| import sys | |
| import os | |
| from dotenv import load_dotenv | |
| # Add backend directory to path to import app modules | |
| backend_path = os.path.abspath(os.path.join(os.getcwd(), 'backend')) | |
| sys.path.append(backend_path) | |
| # Load .env file BEFORE importing app modules | |
| load_dotenv(os.path.join(backend_path, '.env')) | |
| from app.core.database import async_session_factory | |
| from app.models.user import User | |
| from app.core.security import get_password_hash | |
| from sqlalchemy import select | |
| async def check_user(email, new_password): | |
| async with async_session_factory() as session: | |
| result = await session.execute(select(User).where(User.email == email)) | |
| user = result.scalar_one_or_none() | |
| if user: | |
| print(f"User found: {user.email}") | |
| print(f"ID: {user.id}") | |
| print(f"Role: {user.role}") | |
| print(f"Is Active: {user.is_active}") | |
| print(f"Tenant ID: {user.tenant_id}") | |
| print(f"Resetting password for {email} to {new_password}...") | |
| user.hashed_password = get_password_hash(new_password) | |
| user.is_superuser = True # Set superuser flag as requested | |
| await session.commit() | |
| print(f"User updated: Password reset, is_superuser={user.is_superuser}") | |
| else: | |
| print(f"User with email {email} NOT found.") | |
| if __name__ == "__main__": | |
| if len(sys.argv) < 3: | |
| print("Usage: python check_admin_user.py <email> <password>") | |
| sys.exit(1) | |
| email = sys.argv[1] | |
| password = sys.argv[2] | |
| asyncio.run(check_user(email, password)) | |