Spaces:
Running
Running
File size: 1,623 Bytes
e90bf86 | 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 | 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))
|