Esempio n. 1
0
    def wrapper(request, user_id, **kwargs) :
        if 'HTTP_DEVICE_ID' not in request.META :
            result = dict(success=False, message=u'device id is not in the request header')
            return HttpResponse(dumps(result))
        if 'HTTP_SERVER_KEY' not in request.META :
            result = dict(success=False, message=u'server key is not in the request header')
            return HttpResponse(dumps(result))

        device_id = request.META['HTTP_DEVICE_ID']
        server_key = request.META['HTTP_SERVER_KEY']
        key_cache = get_cache('user_key')
        saved_server_key = key_cache.get(device_id)
        
        if server_key != saved_server_key :
            result = dict(success=False, message=u'server key does not match')
            return HttpResponse(dumps(result))

        user_session = get_cache('user_session')
        user_info = user_session.get(server_key)
        if not user_info :
            result = dict(success=False, message=u'need login')
            return HttpResponse(dumps(result))

        saved_user_id = get_user_id(request.META)
        user_id = int(user_id)
        if user_id != saved_user_id :
            result = dict(success=False, message=u'user id does not match with saved user id')
            return HttpResponse(dumps(result))
        return f(request, user_id=user_id, **kwargs)
Esempio n. 2
0
    def wrapper(request, **kwargs) :
        if 'HTTP_DEVICE_ID' not in request.META :
            result = dict(success=False, message=u'device id is not in the request header')
            return HttpResponse(dumps(result))
        if 'HTTP_SERVER_KEY' not in request.META :
            result = dict(success=False, message=u'server key is not in the request header')
            return HttpResponse(dumps(result))

        device_id = request.META['HTTP_DEVICE_ID']
        server_key = request.META['HTTP_SERVER_KEY']
        key_cache = get_cache('user_key')
        saved_server_key = key_cache.get(device_id)
        
        if server_key != saved_server_key :
            result = dict(success=False, message=u'server key does not match')
            return HttpResponse(dumps(result))
        
        user_session = get_cache('user_session')
        user_info = user_session.get(server_key)
        if not user_info :
            result = dict(success=False, message=u'need login')
            return HttpResponse(dumps(result))
        user_info = loads(user_info)
        if not user_info['is_admin'] :
            result = dict(success=False, message=u'you are not an admin')
            return HttpResponse(dumps(result))
        return f(request, **kwargs)
Esempio n. 3
0
def get_image(request, image_id = None) :
    size = dict(
        original = 0,
        thumbnail1 = 1,
        thumbnail2 = 2,
        )
    image_to_send = size['original']
    if 'size' in request.GET :
        image_to_send = size[request.GET['size']]        

    session = get_session()
    image = session.query(Image).get(image_id)
    session.close()

    if not image :
        result = dict(success=False, message=u'images.views.get_image: No image %s' % image_id)
        return HttpResponse(dumps(result))

    if image_to_send == size['original'] :
        return HttpResponse(image.image, mimetype='image/jpeg')
    elif image_to_send == size['thumbnail1'] :
        return HttpResponse(image.thumbnail1_image, mimetype='image/jpeg')
    elif image_to_send == size['thumbnail2'] :
        return HttpResponse(image.thumbnail2_image, mimetype='image/jpeg')
    else :
        return HttpResponse(image.image, mimetype='image/jpeg')
Esempio n. 4
0
def get_images(request):
    limit, offset = get_paginate_info(request.GET)
    session = get_session()
    image_id_list = session.query(Image.image_id).limit(limit).offset(offset).all()
    session.close()
    image_id_list = [ y for x in image_id_list for y in x ]

    data = dict(
        image_list = image_id_list 
        )
    result = dict(success=True, message=u'images.views.get_images: images from {start} to {end}'.format(start=offset, end=offset+limit), data=data)
    return HttpResponse(dumps(result))
Esempio n. 5
0
 def wrapper(request, **kwargs) :
     if request.method == 'POST' :
         return f(request, **kwargs)
     else :
         result = dict(success=False, message=u'only post')
         return HttpResponse(dumps(result))