mirror of
https://github.com/Cp0204/quark-auto-save.git
synced 2026-01-12 07:10:44 +08:00
优化逻辑:使改密码掉登录
This commit is contained in:
parent
e545722b9d
commit
233af1fce9
52
app/run.py
52
app/run.py
@ -10,6 +10,7 @@ from flask import (
|
|||||||
)
|
)
|
||||||
from apscheduler.schedulers.background import BackgroundScheduler
|
from apscheduler.schedulers.background import BackgroundScheduler
|
||||||
from apscheduler.triggers.cron import CronTrigger
|
from apscheduler.triggers.cron import CronTrigger
|
||||||
|
import hashlib
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
|
||||||
@ -24,14 +25,10 @@ app.config["JSON_SORT_KEYS"] = False
|
|||||||
app.config['JSONIFY_PRETTYPRINT_REGULAR'] = False
|
app.config['JSONIFY_PRETTYPRINT_REGULAR'] = False
|
||||||
|
|
||||||
|
|
||||||
# 设置icon
|
def gen_md5(string):
|
||||||
@app.route("/favicon.ico")
|
md5 = hashlib.md5()
|
||||||
def favicon():
|
md5.update(string.encode("utf-8"))
|
||||||
return send_from_directory(
|
return md5.hexdigest()
|
||||||
os.path.join(app.root_path, "static"),
|
|
||||||
"favicon.ico",
|
|
||||||
mimetype="image/vnd.microsoft.icon",
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
# 读取 JSON 文件内容
|
# 读取 JSON 文件内容
|
||||||
@ -47,19 +44,38 @@ def write_json(data):
|
|||||||
json.dump(data, f, indent=4, ensure_ascii=False, sort_keys=False)
|
json.dump(data, f, indent=4, ensure_ascii=False, sort_keys=False)
|
||||||
|
|
||||||
|
|
||||||
|
def is_login():
|
||||||
|
data = read_json()
|
||||||
|
username = data["webui"]["username"]
|
||||||
|
password = data["webui"]["password"]
|
||||||
|
if session.get("login") == gen_md5(username + password):
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
# 设置icon
|
||||||
|
@app.route("/favicon.ico")
|
||||||
|
def favicon():
|
||||||
|
return send_from_directory(
|
||||||
|
os.path.join(app.root_path, "static"),
|
||||||
|
"favicon.ico",
|
||||||
|
mimetype="image/vnd.microsoft.icon",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
# 登录页面
|
# 登录页面
|
||||||
@app.route("/login", methods=["GET", "POST"])
|
@app.route("/login", methods=["GET", "POST"])
|
||||||
def login():
|
def login():
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
data = read_json()
|
data = read_json()
|
||||||
username = request.form.get("username")
|
username = data["webui"]["username"]
|
||||||
password = request.form.get("password")
|
password = data["webui"]["password"]
|
||||||
# 验证用户名和密码
|
# 验证用户名和密码
|
||||||
if (
|
if (username == request.form.get("username")) and (
|
||||||
username == data["webui"]["username"]
|
password == request.form.get("password")
|
||||||
and password == data["webui"]["password"]
|
|
||||||
):
|
):
|
||||||
session["username"] = username
|
session["login"] = gen_md5(username + password)
|
||||||
return redirect(url_for("index"))
|
return redirect(url_for("index"))
|
||||||
else:
|
else:
|
||||||
return render_template("login.html", message="登录失败")
|
return render_template("login.html", message="登录失败")
|
||||||
@ -70,14 +86,14 @@ def login():
|
|||||||
# 退出登录
|
# 退出登录
|
||||||
@app.route("/logout")
|
@app.route("/logout")
|
||||||
def logout():
|
def logout():
|
||||||
session.pop("username", None)
|
session.pop("login", None)
|
||||||
return redirect(url_for("login"))
|
return redirect(url_for("login"))
|
||||||
|
|
||||||
|
|
||||||
# 管理页面
|
# 管理页面
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
def index():
|
def index():
|
||||||
if not session.get("username"):
|
if not is_login():
|
||||||
return redirect(url_for("login"))
|
return redirect(url_for("login"))
|
||||||
return render_template("index.html")
|
return render_template("index.html")
|
||||||
|
|
||||||
@ -85,7 +101,7 @@ def index():
|
|||||||
# 获取配置数据
|
# 获取配置数据
|
||||||
@app.route("/data")
|
@app.route("/data")
|
||||||
def get_data():
|
def get_data():
|
||||||
if not session.get("username"):
|
if not is_login():
|
||||||
return redirect(url_for("login"))
|
return redirect(url_for("login"))
|
||||||
data = read_json()
|
data = read_json()
|
||||||
del data["webui"]
|
del data["webui"]
|
||||||
@ -95,7 +111,7 @@ def get_data():
|
|||||||
# 更新数据
|
# 更新数据
|
||||||
@app.route("/update", methods=["POST"])
|
@app.route("/update", methods=["POST"])
|
||||||
def update():
|
def update():
|
||||||
if not session.get("username"):
|
if not is_login():
|
||||||
return "未登录"
|
return "未登录"
|
||||||
data = read_json()
|
data = read_json()
|
||||||
webui = data["webui"]
|
webui = data["webui"]
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user