登录态改为同一设备 7 天内免重新登录(permanent cookie,访问滑动续期)。
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+3
-1
@@ -26,7 +26,9 @@ APP_USERNAME=admin
|
||||
APP_PASSWORD=CHANGE_ME_STRONG_PASSWORD
|
||||
# 是否关闭登录校验(局域网可设 true;公网务必 false)
|
||||
APP_AUTH_DISABLED=false
|
||||
# Flask 会话密钥(必须替换为长随机字符串)
|
||||
# 登录态保留天数(同一设备 cookie;访问会滑动续期;默认 7)
|
||||
APP_SESSION_DAYS=7
|
||||
# Flask 会话密钥(必须替换为长随机字符串;重启后保持不变才能延续登录)
|
||||
FLASK_SECRET_KEY=CHANGE_TO_LONG_RANDOM_SECRET
|
||||
|
||||
# 企业微信机器人 Webhook(用于行情/风控推送)
|
||||
|
||||
@@ -232,6 +232,13 @@ def resolve_path(path_value):
|
||||
|
||||
app = Flask(__name__)
|
||||
app.secret_key = os.getenv("FLASK_SECRET_KEY") or os.urandom(32)
|
||||
# 登录态:同一设备 7 天内免重新登录(permanent cookie;访问时滑动续期)
|
||||
try:
|
||||
_SESSION_DAYS = max(1, int(os.getenv("APP_SESSION_DAYS", "7") or "7"))
|
||||
except Exception:
|
||||
_SESSION_DAYS = 7
|
||||
app.config["PERMANENT_SESSION_LIFETIME"] = timedelta(days=_SESSION_DAYS)
|
||||
app.config["SESSION_REFRESH_EACH_REQUEST"] = True
|
||||
from lib.instance.instance_embed_lib import attach_embed_templates, redirect_to_embed_shell_if_enabled
|
||||
from lib.instance.instance_static_lib import install_common_static
|
||||
|
||||
@@ -4940,16 +4947,22 @@ def background_task():
|
||||
|
||||
|
||||
# ====================== 登录路由 ======================
|
||||
def _mark_logged_in():
|
||||
session.clear()
|
||||
session.permanent = True
|
||||
session["logged_in"] = True
|
||||
|
||||
|
||||
@app.route("/login", methods=["GET", "POST"])
|
||||
def login():
|
||||
if AUTH_DISABLED:
|
||||
session["logged_in"] = True
|
||||
_mark_logged_in()
|
||||
return redirect("/")
|
||||
if request.method == "POST":
|
||||
username = request.form.get("username")
|
||||
password = request.form.get("password")
|
||||
if username == USERNAME and password == PASSWORD:
|
||||
session["logged_in"] = True
|
||||
_mark_logged_in()
|
||||
return redirect("/")
|
||||
else:
|
||||
flash("账号或密码错误")
|
||||
|
||||
Vendored
+1
@@ -86,6 +86,7 @@ HOT_RELOAD_EXACT = frozenset({
|
||||
"APP_USERNAME",
|
||||
"APP_PASSWORD",
|
||||
"APP_AUTH_DISABLED",
|
||||
"APP_SESSION_DAYS",
|
||||
"WECHAT_WEBHOOK",
|
||||
"HEDGE_PLAN_ENABLED",
|
||||
"HEDGE_PLAN_SHOW_PERP_OPTIONS",
|
||||
|
||||
Reference in New Issue
Block a user