예제 #1
0
파일: auth.py 프로젝트: xThaid/Asylum
    def login():
        json = request.get_json()

        if not validate_json.validate(validate_json.login_schema, json):
            return web_response.bad_request()

        return auth.login(json['login'], json['password'])
예제 #2
0
파일: blinds.py 프로젝트: xThaid/Asylum
    def blinds_instant_action(context):
        json = request.get_json()

        if not validate_json.validate(
                validate_json.blind_instant_action_schema, json):
            return web_response.bad_request()

        for device_id in json['device_ids']:
            asylumd_client.shutterAction(device_id - 1, json['action_id'] - 1)

        return web_response.blinds_action_executed()
예제 #3
0
파일: blinds.py 프로젝트: xThaid/Asylum
    def delete_blinds_task(context):
        json = request.get_json()

        if not validate_json.validate(validate_json.delete_task_schema, json):
            return web_response.bad_request()

        try:
            BlindsTask.query.filter_by(id=json['task_id']).delete()
            db.session.commit()
        except:
            return web_response.database_error()

        return web_response.blinds_task_deleted()
예제 #4
0
    def delete_mac_address(context, user_id):
        if user_id is None:
            user_id = context['user']['id']

        json = request.get_json()
        if not validate_json.validate(validate_json.delete_mac_address_schema, json):
            return web_response.bad_request()

        try:
            MacAddress.query.filter_by(id=json['mac_address_id']).delete()
            db.session.commit()
        except:
            return web_response.database_error()

        return web_response.ok_request()
예제 #5
0
    def add_mac_address(context, user_id):
        if user_id is None:
            user_id = context['user']['id']

        json = request.get_json()

        if not validate_json.validate(validate_json.add_mac_address_schema, json):
            return web_response.bad_request()

        try:
            db.session.add(MacAddress(
                user_id=user_id,
                mac_address=json['mac_address'].lower()
            ))
            db.session.commit()
        except:
            return web_response.database_error()

        return web_response.ok_request()
예제 #6
0
파일: blinds.py 프로젝트: xThaid/Asylum
    def add_blinds_task(context):
        json = request.get_json()

        if not validate_json.validate(validate_json.add_blinds_tasks_schema,
                                      json):
            return web_response.bad_request()

        try:
            db.session.bulk_save_objects(
                list(
                    map(
                        lambda x: BlindsTask(time=json['unix_time'],
                                             device=x,
                                             action=json['action_id'],
                                             user_id=context['user']['id'],
                                             timeout=5 * 60,
                                             active=True),
                        json['devices_ids'])))
            db.session.commit()
        except:
            return web_response.database_error()

        return web_response.blind_task_added()
예제 #7
0
파일: blinds.py 프로젝트: xThaid/Asylum
    def add_blinds_schedule(context):
        json = request.get_json()

        if not validate_json.validate(validate_json.add_blinds_schedule_schema,
                                      json):
            return web_response.bad_request()

        try:
            db.session.bulk_save_objects(
                list(
                    map(
                        lambda x: BlindsSchedule(
                            device=x,
                            action=json['action_id'],
                            hour_type=json['hour_type'],
                            time_offset=json['time_offset'],
                            user_id=context['user']['id']),
                        json['devices_ids'])))

            db.session.commit()
        except:
            return web_response.database_error()

        return web_response.blinds_schedule_added()