Ejemplo n.º 1
0
        def wrapper(request, *args, **kwargs) :
            API_key = extract_api_key(request)
            key = get_api_key(API_key)
            
            if not key :
                json = generate_json_error_msg(-999
                    ,"Error INVALID API Key used please use or register a proper key"
                    ,API_key
                    ,request.method
                    )
                return HttpResponse(json, mimetype='application/json', status=HTTP_UNAUTHORIZED)

            if key.has_all_permissions(permissions) and key.has_access():
                return func( request, *args, **kwargs)

            if not key.has_all_permissions(permissions):
                json = generate_json_error_msg(-997
                    ,"Error this key does not have the permission to access this call"
                    ,API_key
                    ,request.method
                    )
            if not key.has_access():
                json = generate_json_error_msg(-800
                    ,"Error quota exceeded!"
                    ,API_key
                    ,request.method
                    )                
            return HttpResponse(json, mimetype='application/json', status=HTTP_UNAUTHORIZED)
Ejemplo n.º 2
0
    def process_request(self, request):
        if not TokitPath.is_key_required_for(request.path):
            return None

        request_api_key = extract_api_key(request)
        if request_api_key:
            key = get_api_key(request_api_key)
            if key and key.has_access():
                return None

        return HttpResponse("Forbidden", status=401)