36 lines
737 B
Python
36 lines
737 B
Python
import asyncio
|
|
import secrets
|
|
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
from db.session import AsyncSessionLocal
|
|
from core.security import hash_password
|
|
|
|
from domains.users.models import User, UserRole
|
|
|
|
|
|
async def create_admin():
|
|
|
|
username = input("Admin username: ")
|
|
|
|
secret = "1234"
|
|
|
|
async with AsyncSessionLocal() as db:
|
|
|
|
user = User(
|
|
username=username,
|
|
role=UserRole.ADMIN,
|
|
secret_hash=hash_password(secret),
|
|
)
|
|
|
|
db.add(user)
|
|
await db.commit()
|
|
|
|
print("\nAdmin created successfully\n")
|
|
print("Username:", username)
|
|
print("Secret:", secret)
|
|
print("\nSave this secret!\n")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(create_admin()) |