管理页登录系统完成

This commit is contained in:
2023-12-10 21:12:52 +08:00
parent f85cf254ca
commit 3157ccd3a9
3 changed files with 158 additions and 0 deletions

20
main.py
View File

@@ -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"])