更新 app.py
parent
4bad46e43e
commit
b94d91d8b5
18
app/app.py
18
app/app.py
|
|
@ -24,11 +24,14 @@ def register():
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@app.route('/login', methods=['POST'])
|
@app.route('/login', methods=['GET', 'POST'])
|
||||||
def login():
|
def login():
|
||||||
|
if request.method == 'GET':
|
||||||
|
return render_template('login.html')
|
||||||
|
else:
|
||||||
username = request.form['username']
|
username = request.form['username']
|
||||||
password = request.form['password']
|
password = request.form['password']
|
||||||
print(username,password)
|
print(username, password)
|
||||||
# 验证用户名和密码...
|
# 验证用户名和密码...
|
||||||
if valid_login(username, password):
|
if valid_login(username, password):
|
||||||
# 登录成功
|
# 登录成功
|
||||||
|
|
@ -39,6 +42,7 @@ def login():
|
||||||
return jsonify(success=False, message="无效的用户名或密码")
|
return jsonify(success=False, message="无效的用户名或密码")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def valid_login(username, password):
|
def valid_login(username, password):
|
||||||
# 这里应该是验证用户名和密码的逻辑,比如查询数据库等等
|
# 这里应该是验证用户名和密码的逻辑,比如查询数据库等等
|
||||||
# 假设用户名是admin且密码是secret
|
# 假设用户名是admin且密码是secret
|
||||||
|
|
@ -51,9 +55,15 @@ def forget_page():
|
||||||
def home():
|
def home():
|
||||||
if 'username' in session:
|
if 'username' in session:
|
||||||
return render_template('home.html')
|
return render_template('home.html')
|
||||||
|
|
||||||
else:
|
else:
|
||||||
return redirect(url_for('/')) # 如果用户未登录,重定向到登录页面
|
return redirect("login")
|
||||||
|
|
||||||
|
@app.route('/logout')
|
||||||
|
def logout():
|
||||||
|
# 清除session中的所有信息
|
||||||
|
session.clear()
|
||||||
|
# 返回一个响应,或者重定向到登录页面
|
||||||
|
return redirect('/login')
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app.run(debug=True)
|
app.run(debug=True)
|
||||||
|
|
|
||||||
Reference in New Issue