Beispiel #1
0
    def get_all(cls):
        error_message, status, response = DeviceDataController.get_all()

        if error_message:
            return json.dumps({"error_message": error_message}), status
        return json.dumps({"response":
                           ReqParser.as_jsonlist(response)}), status
Beispiel #2
0
    def signin(cls):
        data = json.loads(request.data.decode('utf-8'))
        req_params = ['email', 'password']
        if not ReqParser.check_body(data, req_params):
            return json.dumps({"error_message": "ill-formed request"}), 400

        error_message, status, token = MemberController.signin(data)

        if error_message:
            return json.dumps({"error_message": error_message}), status
        return json.dumps({"token": token}), 200
Beispiel #3
0
    def check_room(cls):
        data = json.loads(request.data.decode('utf-8'))
        req_params = ['roomcode']
        if not ReqParser.check_body(data, req_params):
            return json.dumps({"error_message": "ill-formed request"}), 400

        error_message, status = RoomController.check_room(data['roomcode'])

        if error_message:
            return json.dumps({"error_message": error_message}), status
        return json.dumps({"response": "Success"}), status
Beispiel #4
0
    def register_member(cls):
        data = json.loads(request.data.decode('utf-8'))
        req_params = ["first_name", "last_name", "email", "password", "phone"]
        if not ReqParser.check_body(data, req_params):
            return json.dumps({"error_message": "ill-formed request"}), 400

        error_message, status, token = MemberController.register_member(data)

        if error_message:
            return json.dumps({"error_message": error_message}), status
        return json.dumps({"token": token}), status
Beispiel #5
0
    def collect_data(cls):
        data = json.loads(request.data.decode('utf-8'))
        req_params = ['device_id', 'metadata']
        if not ReqParser.check_body(data, req_params):
            return json.dumps({"error_message": "ill-formed request"}), 400

        error_message, status = DeviceDataController.collect_data(
            data['device_id'], data['metadata'])

        if error_message:
            return json.dumps({"error_message": error_message}), status
        return json.dumps({"response": "Success"}), status
def on_new_entry(data):
    req_params = ["username", "room"]
    if not ReqParser.check_body(data, req_params):
        emit('error', {"error_message": 'invalid params'}, json=True)
    username = data['username']
    room = data['room']
    error, status = RoomController.check_room(room)
    if error:
        emit("error", error)
    error, entry = EntryController.new_entry(room, username)
    if error:
        emit("error", error)
    emit("got_new", entry, room=room)
def delete_entry(data):
    req_params = ["username", "room", "target"]
    if not ReqParser.check_body(data, req_params):
        emit('error', {"error_message": 'invalid params'}, json=True)
    username = data['username']
    room = data['room']
    target = data['target']
    error = EntryController.delete_entry(target)
    if error:
        emit("error", error)
    error, response = EntryController.for_room(room)
    if error:
        emit("error", error)
    emit("all_entries", response, room=room)
Beispiel #8
0
    def register_device(cls):
        # Requires factory reset auth, super user authority

        data = json.loads(request.data.decode('utf-8'))
        req_params = ['device_id']
        if not ReqParser.check_body(data, req_params):
            return json.dumps({"error_message": "ill-formed request"}), 400

        error_message, status = DeviceDataController.create_shadow(
            data['device_id'])

        if error_message:
            return json.dumps({"error_message": error_message}), status
        return json.dumps({"response": "Success"}), status
Beispiel #9
0
    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
Beispiel #10
0
    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
Beispiel #11
0
    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
Beispiel #12
0
    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
Beispiel #13
0
    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 on_join(data):
    req_params = ["username", "room"]
    if not ReqParser.check_body(data, req_params):
        emit('error', {"error_message": 'invalid params'}, json=True)
    username = data['username']
    room = data['room']
    error, status = RoomController.check_room(room)
    if error:
        send("error", error)
    error, status = RoomController.join_room(room, username)
    if error:
        send("error", error)
    else:
        join_room(room)
    error, entries = EntryController.for_room(room)
    emit("all_entries", entries, room=room)
Beispiel #15
0
    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
Beispiel #16
0
    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
Beispiel #17
0
    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
Beispiel #18
0
    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