mirror of
https://github.com/Kakune55/PyGetGPT.git
synced 2025-12-14 08:13:55 +08:00
管理页登录系统完成
This commit is contained in:
20
main.py
20
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"])
|
||||
Reference in New Issue
Block a user