From 3157ccd3a91b852331bbdec2efe5341f57399cb8 Mon Sep 17 00:00:00 2001 From: Kakune55 Date: Sun, 10 Dec 2023 21:12:52 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AE=A1=E7=90=86=E9=A1=B5=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 20 ++++++++++++ templates/login.html | 65 ++++++++++++++++++++++++++++++++++++++ templates/status.html | 73 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 158 insertions(+) create mode 100644 templates/login.html create mode 100644 templates/status.html diff --git a/main.py b/main.py index a626ca9..156b0e3 100644 --- a/main.py +++ b/main.py @@ -5,6 +5,7 @@ from apiModule import qwenTurbo , chatglmTurbo , gpt35Turbo , gpt4Turbo app = flask.Flask(__name__) CORS(app,origins="*") +app.secret_key = b'SQ-{kJE;m(jEBi|{yq]v' @app.route('/api/user', methods=['POST']) def post_data(): @@ -49,10 +50,29 @@ def post_data(): db.reduce_value(userRequest['userkey'], tokenUsed) return {"code":code,"output":output,"surplus":surplusToken} + @app.route('/') def index(): return flask.render_template('index.html') +@app.route('/login', methods=['POST','GET']) +def login(): + if flask.request.method == 'GET': + return flask.render_template('login.html') + userRequest = flask.request.form + if userRequest["password"] != config.readConf()["appconf"]["adminkey"]: + return flask.render_template('login.html') + flask.session["admin"] = True + return flask.redirect(flask.url_for('admin')) + + +@app.route('/admin') +def admin(): + if "admin" in flask.session : + return "管理页" + return "未登录" + + if __name__ == '__main__': app.run(debug=bool(config.readConf()["appconf"]["debug"]),host=config.readConf()["appconf"]["host"],port=config.readConf()["appconf"]["port"]) \ No newline at end of file diff --git a/templates/login.html b/templates/login.html new file mode 100644 index 0000000..9710968 --- /dev/null +++ b/templates/login.html @@ -0,0 +1,65 @@ + + + + + + + 登录页面 + + + + +
+

登录

+
+ + +
+
+ + + + + \ No newline at end of file diff --git a/templates/status.html b/templates/status.html new file mode 100644 index 0000000..141ea68 --- /dev/null +++ b/templates/status.html @@ -0,0 +1,73 @@ + + + + +网站后台展示页 + + + +
+

网站后台展示页

+ + + + + + + + + + + + + + + + + + + + + + + + + +
项目状态
网站访问速度正常
数据库连接正常
服务器负载较高
在线用户数正常
+
+ + + +