示例#1
0
 def has_permission(self, request, view):
     try:
         if request.method == 'GET':
             return True
         r = AuthRequester()
         response, status_code = r.get_user_info(
             r.get_token_from_request(request))
         auth_json = r.get_data_from_response(response)
         print(auth_json)
         try:
             return int(view.kwargs[view.lookup_url_kwarg]
                        ) == auth_json['id'] or auth_json['is_superuser']
         except KeyError:
             return False
     except BaseApiRequestError:
         return False
示例#2
0
class IsAuthenticated(BaseAuthPermission):
    AUTH_REQUESTER = AuthRequester()

    def has_permission(self, request, view):
        token = self.AUTH_REQUESTER.get_token_from_request(request)
        if token is None:
            return False
        return AuthRequester().is_token_valid(token)[1]
示例#3
0
 def delete_billing(self, uuid, token=None):
     headers = {}
     if token:
         headers = AuthRequester()._create_auth_header(token)
     response = self.delete_request(self.BILLING_HOST + str(uuid) + '/',
                                    headers=headers)
     if response is None:
         return self.BASE_HTTP_ERROR
     return self.get_data_from_response(response), response.status_code
示例#4
0
class IsAppTokenCorrect(BaseAuthPermission):
    AUTH_REQUESTER = AuthRequester()

    def has_permission(self, request, view):
        token = self.AUTH_REQUESTER.get_token_from_request(request)
        if token is None:
            return False
        view.app_access_token = token
        return AuthRequester().app_verify_token(token)[1]
示例#5
0
 def post_billing(self, data={}, token=None):
     headers = {}
     if token:
         headers = AuthRequester()._create_auth_header(token)
     response = self.post_request(self.BILLING_HOST,
                                  data=data,
                                  headers=headers)
     if response is None:
         return self.BASE_HTTP_ERROR
     return response, response.status_code
示例#6
0
    def get_billing(self, uuid, token=None):
        headers = {}
        print(uuid)
        if token:
            headers = AuthRequester()._create_auth_header(token)
        response = self.get_request(self.BILLING_HOST + str(uuid) + '/',
                                    headers=headers)
        if response is None:
            return self.BASE_HTTP_ERROR
        #print(response.json())

        return response, response.status_code
示例#7
0
class IsSuperuser(BaseAuthPermission):
    AUTH_REQUESTER = AuthRequester()

    def has_permission(self, request, view):
        print(2)
        token = self.AUTH_REQUESTER.get_token_from_request(request)
        if token is None:
            return False
        response, response_status_code = self.AUTH_REQUESTER.get_user_info(
            token)
        response_data = self.AUTH_REQUESTER.get_data_from_response(response)
        try:
            print(response_data['is_superuser'])
            return response_data['is_superuser']
        except KeyError:
            return False
示例#8
0
 def has_permission(self, request, view):
     token = self.AUTH_REQUESTER.get_token_from_request(request)
     if token is None:
         return False
     view.app_access_token = token
     return AuthRequester().app_verify_token(token)[1]
示例#9
0
 def has_permission(self, request, view):
     token = self.AUTH_REQUESTER.get_token_from_request(request)
     if token is None:
         return False
     return AuthRequester().is_token_valid(token)[1]