支持使用python app.py user admin password修改密码
This commit is contained in:
parent
e6614e94a6
commit
ef39536ed9
28
app.py
28
app.py
@ -12,6 +12,7 @@ from werkzeug.utils import secure_filename
|
||||
import requests
|
||||
from urllib.parse import urlparse
|
||||
from math import ceil
|
||||
import argparse
|
||||
|
||||
app = Flask(__name__)
|
||||
app.secret_key = 'your_secret_key_here' # 请更改为安全的密钥
|
||||
@ -1022,5 +1023,30 @@ def api_categories():
|
||||
|
||||
return jsonify(sorted_categories)
|
||||
|
||||
def change_password(username, new_password):
|
||||
settings = load_settings()
|
||||
|
||||
if username == 'admin':
|
||||
settings['admin_password_hash'] = generate_password_hash(new_password, method='pbkdf2:sha256')
|
||||
save_settings(settings)
|
||||
print(f"管理员 {username} 的密码已成功修改!")
|
||||
else:
|
||||
print("错误:只能修改管理员 (admin) 的密码")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(debug=True, port='8094', host='0.0.0.0')
|
||||
parser = argparse.ArgumentParser(description='导航系统管理工具')
|
||||
subparsers = parser.add_subparsers(dest='command', help='可用命令')
|
||||
|
||||
# 添加 user 子命令
|
||||
user_parser = subparsers.add_parser('user', help='用户管理')
|
||||
user_parser.add_argument('username', help='用户名')
|
||||
user_parser.add_argument('password', help='新密码')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.command == 'user':
|
||||
change_password(args.username, args.password)
|
||||
else:
|
||||
# 如果没有指定命令行参数,则运行 Flask 应用
|
||||
app.run(debug=True, port='8094', host='0.0.0.0')
|
||||
@ -10,6 +10,6 @@
|
||||
"logo_icon": "fa-solid fa-th-list",
|
||||
"logo_image": "/upload/logo/f40e2eb965b2.png",
|
||||
"dark_bg_rotate": false,
|
||||
"admin_password_hash": "scrypt:32768:8:1$mPFCfRRzOrcjE6z3$e72ef50a2d3f7292f64bcfc5e21f32c95ea8665414ea8d5f6b216735d68f151166c99fae21132c7949bd92ea32041f969cd4a471adb110a99328089541f7dccb",
|
||||
"admin_password_hash": "pbkdf2:sha256:260000$ig0vNC2QdipLHgAy$6d734e5112bbdf94bc5cb49a38ca4764376ebb51c877a416d1a8f27d5fb5c415",
|
||||
"footer_html": "<div class=\"flex flex-col items-center text-slate-400 text-sm py-4\" style=\"margin-top:10px\">\r\n <div class=\"flex items-center\">\r\n <span>© 2023 AIDaohang. All rights reserved.</span>\r\n <span class=\"mx-2\">|</span>\r\n <span>Powered by <a href=\"https://github.com\" target=\"_blank\" class=\"hover:text-slate-200 ml-1\">AIDaohang</a></span>\r\n </div>\r\n</div>"
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user