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 @@ + + + +
+ + +项目 | +状态 | +
---|---|
网站访问速度 | +正常 | +
数据库连接 | +正常 | +
服务器负载 | +较高 | +
在线用户数 | +正常 | +