def resend_verification(cls): err, status, member_id, fam_id = Auth.whoisit(request.headers) if err and err != 'Not a verified member': return json.dumps({"error_message": err}), status error_message, status = VerificationController.resend_verification( member_id) if error_message: return json.dumps({"error_message": error_message}), status return json.dumps({"response": "Success!"}), status
def get_profile(cls): err, status, member_id, fam_id = Auth.whoisit(request.headers) if err: return json.dumps({"error_message": err}), status error_message, status, response = MemberController.get_profile( fam_id, member_id) if error_message: return json.dumps({"error_message": error_message}), status return json.dumps({"response": response}), status
def get_cart(cls): err, status, member_id, fam_id = Auth.whoisit(request.headers) if err: return json.dumps({"error_message": err}), 400 error_message, status, response = ListToCartController.get_cart(fam_id) if error_message: return json.dumps({"error_message": error_message}), status return json.dumps({ "response": list(map(lambda x: x.json() if x else None, response)) }), status
def register_family(cls): err, status, member_id, fam_id = Auth.whoisit(request.headers) if err and err != 'Not registered to family': return json.dumps({"error_message": err}), 400 data = json.loads(request.data.decode('utf-8')) req_params = ['address_line1', 'address_line2', 'city', 'state', 'zip_code', 'name'] if not ReqParser.check_body(data, req_params): return json.dumps({"error_message": "ill-formed request"}), 400 error_message, status, response = FamilyController.register_family(data, member_id) if error_message: return json.dumps({"error_message": error_message}), status return json.dumps({"response": response}), status
def invite_by_email(cls): err, status, member_id, fam_id = Auth.whoisit(request.headers) if err: return json.dumps({"error_message": err}), 400 data = json.loads(request.data.decode('utf-8')) req_params = ['admin', 'member'] if not ReqParser.check_body(data, req_params): return json.dumps({"error_message": "ill-formed request"}) error_message, status = FamilyController.invite_by_email(data['admin'], data['member'], fam_id) if error_message: return json.dumps({"error_message": error_message}), status return json.dumps({"response": "Success"}), status
def verify_member(cls): err, status, member_id, fam_id = Auth.whoisit(request.headers) if err and err != 'Not a verified member': return json.dumps({"error_message": err}), status data = json.loads(request.data.decode('utf-8')) req_params = ["verification_code"] if not ReqParser.check_body(data, req_params): return json.dumps({"error_message": "ill-formed request"}), 400 error_message, status = VerificationController.verify_member( data['verification_code'], member_id) if error_message: return json.dumps({"error_message": error_message}), status return json.dumps({"response": "Success!"}), status
def register_list_to_cart(cls): err, status, member_id, fam_id = Auth.whoisit(request.headers) if err: return json.dumps({"error_message": err}), 400 data = json.loads(request.data.decode('utf-8')) req_params = ["alias", "in_store"] if not ReqParser.check_body(data, req_params): return json.dumps({"error_message": "ill-formed request"}), 400 error_message, status = ListToCartController.register_list( member_id, fam_id, data['alias'], data['in_store']) if error_message: return json.dumps({"error_message": error_message}), status return json.dumps({"response": "Success!"}), status
def checkout(cls): err, status, member_id, fam_id = Auth.whoisit(request.headers) if err: return json.dumps({"error_message": err}), status data = json.loads(request.data.decode('utf-8')) req_params = ['total', 'items'] if not ReqParser.check_body(data, req_params): return json.dumps({"error_message": "ill-formed request"}), 400 error_message, status = CheckoutController.checkout( member_id, fam_id, data['total'], data['items']) if error_message: return json.dumps({"error_message": error_message}), status return json.dumps({"response": "Success!"}), 200
def signin_by_token(cls): err, status, member_id, fam_id = Auth.whoisit(request.headers) if err: if member_id == 0: return json.dumps({"error_message": err}), status else: return json.dumps({"response": err}), 200 auth_header = request.headers.get('Authorization') error_message, status, token = MemberController.update_token( auth_header.split(" ")[1]) if error_message: return json.dumps({"error_message": error_message}), status return json.dumps({"response": token, "uid": member_id}), status
def edit_niche(cls): err, status, member_id, fam_id = Auth.whoisit(request.headers) if err: return json.dumps({"error_message": err}), 400 data = json.loads(request.data.decode('utf-8')) req_params = [ 'device_id', 'alert_level', 'container', 'alias', 'auto_order_store', 'product_metadata' ] if not ReqParser.check_body(data, req_params): return json.dumps({"error_message": "ill-formed request"}), 400 error_message, status = DeviceDataController.edit_niche(fam_id, data) if error_message: return json.dumps({"error_message": error_message}), status return json.dumps({"response": "Success"}), status
def delete_cart(cls): err, status, member_id, fam_id = Auth.whoisit(request.headers) if err: return json.dumps({"error_message": err}), 400 data = json.loads(request.data.decode('utf-8')) req_params = ["victim_ids"] if not ReqParser.check_body(data, req_params): return json.dumps({"error_message": "ill-formed request"}), 400 error_message, status, response = ListToCartController.delete_cart( fam_id, data['victim_ids']) if error_message: return json.dumps({"error_message": error_message}), status return json.dumps({ "response": list(map(lambda x: x.json() if x else None, response)) }), status
def change_shadow_fam(cls): """ allow other users to change when this scenario becomes common """ err, status, member_id, fam_id = Auth.whoisit(request.headers) if err: return json.dumps({"error_message": err}), status data = json.loads(request.data.decode('utf-8')) req_params = ['secret', 'device_id'] if not ReqParser.check_body(data, req_params): return json.dumps({"error_message": "ill-formed request"}), 400 error_message, status = DeviceDataController.change_shadow_fam( fam_id, data) if error_message: return json.dumps({"error_message": error_message}), status return json.dumps({"response": "Success"}), status
def edit_list_to_cart(cls): err, status, member_id, fam_id = Auth.whoisit(request.headers) if err: return json.dumps({"error_message": err}), 400 data = json.loads(request.data.decode('utf-8')) req_params = [ "alias", "in_cart", "in_store", "item_name", "item_image", "item_price", "item_quantity", "list_to_cart_id" ] if not ReqParser.check_body(data, req_params): return json.dumps({"error_message": "ill-formed request"}), 400 error_message, status = ListToCartController.edit_list_to_cart( fam_id, data) if error_message: return json.dumps({"error_message": error_message}), status return json.dumps({"response": "Success"}), status