from flask import Flask, request, jsonify
from flask_jwt_extended import JWTManager, create_access_token
app = Flask(__name__)
app.config['JWT_SECRET_KEY'] = 'secret'
jwt = JWTManager(app)
@app.route('/login', methods=['POST'])
def login():
username = request.json.get('username')
password = request.json.get('password')
# 验证逻辑省略
access_token = create_access_token(identity=username)
return jsonify(access_token=access_token), 200
]]>
@app.route('/search_alumni', methods=['GET'])
def search_alumni():
major = request.args.get('major')
year = request.args.get('year')
query = "SELECT * FROM alumni_info WHERE major=:major AND year=:year"
result = db.execute(query, {"major": major, "year": year})
return jsonify(result.fetchall()), 200
]]>