Files
qihuo/reset_admin.py

30 lines
1.2 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Copyright (c) 2025-2026 马建军. All rights reserved.
# 专有软件 — 未经授权禁止复制、传播、转售。
# 严禁用于:带单/代客理财、向他人推荐期货品种或买卖建议、融资配资等业务。
# 详见 LICENSE.zh-CN.txt 与 docs/软件购买与使用协议.md
#!/usr/bin/env python3
"""从 .env 重置管理员账号(服务器上忘记密码时使用)"""
import os
import sys
from dotenv import load_dotenv
from werkzeug.security import generate_password_hash
BASE = os.path.dirname(os.path.abspath(__file__))
load_dotenv(os.path.join(BASE, ".env"))
sys.path.insert(0, BASE)
from app import set_setting, get_setting # noqa: E402
username = os.getenv("ADMIN_USERNAME", "admin").strip() or "admin"
password = os.getenv("ADMIN_PASSWORD", "").strip()
if not password or password == "change-me-on-first-login":
print("请在 .env 中设置 ADMIN_PASSWORD 后再运行此脚本")
sys.exit(1)
old_username = get_setting("admin_username")
set_setting("admin_username", username)
set_setting("admin_password_hash", generate_password_hash(password))
print(f"已重置管理员: {username}(原账号: {old_username or ''}")