Spaces:
Running
Running
File size: 1,671 Bytes
f1c284f | 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 | """
Script to update user to admin status and/or reset password.
Run: python backend/scripts/make_admin.py
"""
import asyncio
import sys
import os
# Add backend to path
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
from sqlmodel import select
from sqlmodel.ext.asyncio.session import AsyncSession
from app.core.database import get_session, engine
from app.models.user import User
async def make_admin(email: str, new_password: str = None):
"""Make user a superuser and optionally reset password."""
async with AsyncSession(engine) as session:
# Find user
stmt = select(User).where(User.email == email)
result = await session.execute(stmt)
user = result.scalar_one_or_none()
if not user:
print(f"❌ User not found: {email}")
return False
# Update to superuser
user.is_superuser = True
user.is_verified = True
user.is_active = True
# Update password if provided
if new_password:
user.hashed_password = User.get_password_hash(new_password)
print(f"✅ Password updated for {email}")
session.add(user)
await session.commit()
print(f"✅ User {email} is now superuser (admin)")
print(f" ID: {user.id}")
print(f" Tenant: {user.tenant_id}")
print(f" is_superuser: {user.is_superuser}")
print(f" is_verified: {user.is_verified}")
return True
if __name__ == "__main__":
email = "axeroni.s2@gmail.com"
password = "vector7678"
asyncio.run(make_admin(email, password))
|