示例#1
0
def obtain_state_all(request, deviceid):
    current_user_id = request.user.id
    if _DEBUG:
        if current_user_id is None:
            current_user_id = _DEBUG_USER_ID
    if not auth_selectors.userid_matches_deviceid(current_user_id, deviceid):
        return HttpResponse('Unauthorized to view this property', status=401)
    data = serializers.serialize(selectors.obtain_state_all(deviceid))
    return HttpResponse(data, content_type='application/json')
示例#2
0
def save_state(request):
    try:
        body_json = json.loads(request.body)
        deviceid = body_json["deviceid"]
        current_user_id = request.user.id
        if _DEBUG:
            if current_user_id is None:
                current_user_id = _DEBUG_USER_ID
        if not auth_selectors.userid_matches_deviceid(current_user_id,
                                                      deviceid):
            return HttpResponse('Unauthorized to view this property',
                                status=401)
        state = body_json["state"]
        value = body_json["value"]
        services.save_state(deviceid, state, value)
    except KeyError:
        return HttpResponse(400)
    return HttpResponse(200)