I'm trying to set up an API login of sorts that when the login is successful, it returns an JWT and first/last name sent with the login from the POST request. My problem is that I cant figure out a way that works to return the first/last name variables to another Class and function. This my code:
@app.route('/login', methods=['POST'])
def login():
if not request.is_json:
return jsonify({"msg": "Missing JSON in request"}), 400
username = request.json.get('username', None)
password = request.json.get('password', None)
client_fname = request.json.get('Client First Name', None)
client_lname = request.json.get('Client Last Name', None)
if not username:
return jsonify({"msg": "Missing username parameter"}), 400
if not password:
return jsonify({"msg": "Missing password parameter"}), 400
if username != USER_DATA.get(username) and password not in USER_DATA[username]:
return jsonify({"msg": "Bad username or password"}), 401
access_token = create_access_token(identity=username)
return jsonify(access_token=access_token), 200, PrivateResource.sendData(self, client_fname, client_lname)
class PrivateResource(Resource):
@app.route('/protected', methods=['GET'])
@jwt_required
def sendData(self, client_fname, client_lname):
return mysqldb.addUser("{}".format(client_fname),"{}".format(client_lname))
I want to return client_fname
and client_lname
so I can then use them with sendData()
. How can I achieve this without have issues with unicode from json or passing the variables?