19 lines
585 B
Python
19 lines
585 B
Python
# 文件已删除,admin 创建脚本不再需要。
|
||
from passlib.context import CryptContext
|
||
|
||
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
|
||
db = database.SessionLocal()
|
||
|
||
# 删除已有 admin
|
||
admin = db.query(models.User).filter(models.User.username == "admin").first()
|
||
if admin:
|
||
db.delete(admin)
|
||
db.commit()
|
||
|
||
hashed_password = pwd_context.hash("admin123")
|
||
admin_user = models.User(username="admin", hashed_password=hashed_password, is_admin=True, is_active=True, balance=100)
|
||
db.add(admin_user)
|
||
db.commit()
|
||
db.close()
|
||
print("admin 管理员已插入!")
|