You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
19 lines
742 B
19 lines
742 B
from flask import Blueprint, request, jsonify
|
|
from ZhuQue.Db.db import execute_query
|
|
|
|
# 注册蓝图
|
|
auth_blueprint = Blueprint('auth', __name__)
|
|
|
|
|
|
@auth_blueprint.route('/login', methods=['POST'])
|
|
def login():
|
|
username = request.form['username'] # POST参数需要这样接收
|
|
password = request.form['password']
|
|
|
|
# 使用封装的 execute_query 函数查询用户
|
|
user = execute_query("SELECT * FROM users WHERE username = %s", (username,), one=True)
|
|
if user and user['password'] == password: # 假设密码以明文存储,实际应用中应使用哈希
|
|
return jsonify({'message': 'Login successful'}), 200
|
|
else:
|
|
return jsonify({'message': 'Invalid username or password'}), 401
|