feat: bootstrap admin from NAV_ADMIN_USERNAME and NAV_ADMIN_PASSWORD
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -254,12 +254,18 @@ def _group_choices():
|
||||
def _ensure_default_user() -> None:
|
||||
if User.query.count() > 0:
|
||||
return
|
||||
u = User(username="admin")
|
||||
u.set_password("admin123")
|
||||
username = (os.environ.get("NAV_ADMIN_USERNAME") or "admin").strip() or "admin"
|
||||
password = os.environ.get("NAV_ADMIN_PASSWORD") or "admin123"
|
||||
u = User(username=username)
|
||||
u.set_password(password)
|
||||
db.session.add(u)
|
||||
db.session.add(ServiceGroup(name="默认分组", sort_order=0))
|
||||
db.session.commit()
|
||||
print("[nav] 首次运行:默认账号 admin 密码 admin123(仅内网使用,建议自行改库或删用户后重建)")
|
||||
print(
|
||||
f"[nav] 首次运行:已创建管理员「{username}」"
|
||||
"(来自 NAV_ADMIN_USERNAME / NAV_ADMIN_PASSWORD,未设置则为 admin / admin123)。"
|
||||
"生产环境请尽快改为强密码。"
|
||||
)
|
||||
|
||||
|
||||
app = create_app()
|
||||
|
||||
Reference in New Issue
Block a user