new changes
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -14,12 +14,19 @@ from app.core.security import get_password_hash
|
||||
from app.models.user import User
|
||||
|
||||
|
||||
async def seed():
|
||||
async def seed(*, reset_password: bool = False):
|
||||
await init_db()
|
||||
async with AsyncSessionLocal() as db:
|
||||
result = await db.execute(select(User).where(User.username == "admin"))
|
||||
if result.scalar_one_or_none():
|
||||
print("Admin user already exists")
|
||||
existing = result.scalar_one_or_none()
|
||||
if existing:
|
||||
if reset_password:
|
||||
existing.password = get_password_hash("admin")
|
||||
existing.is_active = True
|
||||
await db.commit()
|
||||
print("Admin password reset: username=admin, password=admin")
|
||||
else:
|
||||
print("Admin user already exists (use --reset-password to force admin/admin)")
|
||||
return
|
||||
admin = User(
|
||||
username="admin",
|
||||
@@ -32,4 +39,5 @@ async def seed():
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(seed())
|
||||
reset = "--reset-password" in sys.argv
|
||||
asyncio.run(seed(reset_password=reset))
|
||||
|
||||
Reference in New Issue
Block a user