def logout_user(): auth_header = request.headers.get("Authorization") res = {"status": "fail", "message": "Token invalid."} if auth_header: auth_token = auth_header.split(" ")[1] response = User.decode_auth_token(auth_token) if not isinstance(response, str): res["status"] = "success" res["message"] = "Successfully logged out." return jsonify(res), 200 else: res["message"] = response return jsonify(res), 401 else: return jsonify(res), 403
def logout_user(): # get auth token auth_header = request.headers.get("Authorization") response_object = {"status": "fail", "message": "Provide a valid auth token."} if auth_header: auth_token = auth_header.split(" ")[1] resp = User.decode_auth_token(auth_token) if not isinstance(resp, str): response_object["status"] = "success" response_object["message"] = "Successfully logged out." return jsonify(response_object), 200 else: response_object["message"] = resp return jsonify(response_object), 401 else: return jsonify(response_object), 403
def get_user_status(): # get auth token auth_header = request.headers.get("Authorization") response_object = {"status": "fail", "message": "Provide a valid auth token."} if auth_header: auth_token = auth_header.split(" ")[1] resp = User.decode_auth_token(auth_token) if not isinstance(resp, str): user = User.query.filter_by(id=resp).first() response_object["status"] = "success" response_object["message"] = "Success." response_object["data"] = user.to_json() return jsonify(response_object), 200 response_object["message"] = resp return jsonify(response_object), 401 else: return jsonify(response_object), 401
def get_user_status(): auth_header = request.headers.get("Authorization") res = {"status": "fail", "message": "Token invalid."} if auth_header: auth_token = auth_header.split(" ")[1] response = User.decode_auth_token(auth_token) if not isinstance(response, str): user = User.query.filter_by(id=response).first() res["status"] = "success" res["message"] = "Success." res["data"] = user.to_json() return jsonify(res), 200 else: res["message"] = response return jsonify(res), 401 else: return jsonify(res), 401
def test_decode_auth_token(test_app): user = add_user("justatest", "*****@*****.**", "test") auth_token = user.encode_auth_token(user.id) assert isinstance(auth_token, bytes) assert User.decode_auth_token(auth_token) == user.id