當前位置: 首頁>>代碼示例>>Python>>正文


Python permissions.IsAuthenticated方法代碼示例

本文整理匯總了Python中rest_framework.permissions.IsAuthenticated方法的典型用法代碼示例。如果您正苦於以下問題:Python permissions.IsAuthenticated方法的具體用法?Python permissions.IsAuthenticated怎麽用?Python permissions.IsAuthenticated使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在rest_framework.permissions的用法示例。


在下文中一共展示了permissions.IsAuthenticated方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_auth_required

# 需要導入模塊: from rest_framework import permissions [as 別名]
# 或者: from rest_framework.permissions import IsAuthenticated [as 別名]
def test_auth_required(rf):
    class RestrictedPersonViewSet(PersonViewSet):
        permission_classes = [IsAuthenticated]

    data = dump_json({"people": {"name": "Jason Api"}})

    request = rf.post(
        reverse("person-list"), data=data,
        content_type="application/vnd.api+json")
    view = RestrictedPersonViewSet.as_view({'post': 'create'})
    response = view(request)
    response.render()

    assert response.status_code == 403, response.content
    assert not models.Person.objects.exists()

    results = {
        "errors": [{
            "status": "403",
            "title": "Authentication credentials were not provided."
        }]
    }
    assert response.content == dump_json(results) 
開發者ID:kevin-brown,項目名稱:drf-json-api,代碼行數:25,代碼來源:test_errors.py

示例2: add_viewset

# 需要導入模塊: from rest_framework import permissions [as 別名]
# 或者: from rest_framework.permissions import IsAuthenticated [as 別名]
def add_viewset(table):
    data_index = table.name
    record_data_index = "{}.".format(table.name)
    deleted_data_index = "{}..".format(table.name)

    def retrieve(self, request, *args, **kwargs):
        try:
            res = es.search(index=record_data_index, doc_type="record-data", body={"query": {"term": {"S-data-id": kwargs["pk"]}}}, sort="S-update-time:desc")
        except NotFoundError as exc:
            raise exceptions.NotFound("Document {} was not found in Type data of Index {}".format(kwargs["pk"], record_data_index))
        except TransportError as exc:
            return Response([])
        return Response(res["hits"])
    viewset = type(table.name, (mixins.RetrieveModelMixin, viewsets.GenericViewSet), dict(
        permission_classes=(permissions.IsAuthenticated, ), retrieve=retrieve))
    setattr(views, table.name, viewset)
    return viewset 
開發者ID:open-cmdb,項目名稱:cmdb,代碼行數:19,代碼來源:initialize.py

示例3: get

# 需要導入模塊: from rest_framework import permissions [as 別名]
# 或者: from rest_framework.permissions import IsAuthenticated [as 別名]
def get(self, request):
        """Get"""
        quest = Question.objects.filter(test_id=request.GET.get("pk", None)).order_by("-id")
        counter = CompleteQuestion().get_counter(request.user, request.GET.get("pk", None))
        serializer = QuestionSerializer(quest, many=True)
        return JsonResponse(serializer.data, safe=False)


# class QuestionsInTest(BlankGetAPIView):
#     """
#     Вывод вопросов в отдельном тесте,
#     параметр: pk, значение: id теста, вопросы которого нужны
#     """
#     permission_classes = [permissions.IsAuthenticated]
#     model = Question
#     serializer = QuestionSerializer
#     filter_name = 'test_id'
#     order_params = 'id' 
開發者ID:DJWOMS,項目名稱:djangochannel,代碼行數:20,代碼來源:api_views.py

示例4: test_bearer_authentication

# 需要導入模塊: from rest_framework import permissions [as 別名]
# 或者: from rest_framework.permissions import IsAuthenticated [as 別名]
def test_bearer_authentication(self):
        @api_view(['GET'])
        @permission_classes([IsAuthenticated])
        @authentication_classes([BearerAuthentication])
        def my_view(request):
            return Response({})

        request = self.factory.get('/')
        response = my_view(request)
        self.assertEqual(response.status_code, 401)

        token = self._obtain_auth_token()
        request = self.factory.get('/', HTTP_AUTHORIZATION=f'Bearer {token}')
        response = my_view(request)
        self.assertEqual(response.status_code, 200) 
開發者ID:openwisp,項目名稱:openwisp-users,代碼行數:17,代碼來源:test_authentication.py

示例5: get_permissions

# 需要導入模塊: from rest_framework import permissions [as 別名]
# 或者: from rest_framework.permissions import IsAuthenticated [as 別名]
def get_permissions(self):
        """Assign permission based on action."""
        permissions = [IsAuthenticated, IsActiveCircleMember]
        if self.action in ['update', 'partial_update', 'finish']:
            permissions.append(IsRideOwner)
        if self.action == 'join':
            permissions.append(IsNotRideOwner)
        return [p() for p in permissions] 
開發者ID:pablotrinidad,項目名稱:cride-platzi,代碼行數:10,代碼來源:rides.py

示例6: get_permissions

# 需要導入模塊: from rest_framework import permissions [as 別名]
# 或者: from rest_framework.permissions import IsAuthenticated [as 別名]
def get_permissions(self):
        """Assign permissions based on action."""
        permissions = [IsAuthenticated]
        if self.action != 'create':
            permissions.append(IsActiveCircleMember)
        if self.action == 'invitations':
            permissions.append(IsSelfMember)
        return [p() for p in permissions] 
開發者ID:pablotrinidad,項目名稱:cride-platzi,代碼行數:10,代碼來源:memberships.py

示例7: get_permissions

# 需要導入模塊: from rest_framework import permissions [as 別名]
# 或者: from rest_framework.permissions import IsAuthenticated [as 別名]
def get_permissions(self):
        """Assign permissions based on action."""
        permissions = [IsAuthenticated]
        if self.action in ['update', 'partial_update']:
            permissions.append(IsCircleAdmin)
        return [permission() for permission in permissions] 
開發者ID:pablotrinidad,項目名稱:cride-platzi,代碼行數:8,代碼來源:circles.py

示例8: get_permissions

# 需要導入模塊: from rest_framework import permissions [as 別名]
# 或者: from rest_framework.permissions import IsAuthenticated [as 別名]
def get_permissions(self):
        if self.action == 'list' or self.action == 'retrieve':
            permission_classes = [permissions.IsAuthenticated]
        else:
            permission_classes = [permissions.IsAdminUser]
        return [permission() for permission in permission_classes] 
開發者ID:82Flex,項目名稱:DCRM,代碼行數:8,代碼來源:user.py

示例9: get_permissions

# 需要導入模塊: from rest_framework import permissions [as 別名]
# 或者: from rest_framework.permissions import IsAuthenticated [as 別名]
def get_permissions(self):
        if self.action == 'partial_update' or self.action == 'update':
            permission_classes = [permissions.IsAdminUser]
        elif self.action == 'list' or self.action == 'retrieve':
            permission_classes = [permissions.IsAuthenticated]
        else:
            permission_classes = [DenyAny]
        return [permission() for permission in permission_classes] 
開發者ID:82Flex,項目名稱:DCRM,代碼行數:10,代碼來源:setting.py

示例10: get_permissions

# 需要導入模塊: from rest_framework import permissions [as 別名]
# 或者: from rest_framework.permissions import IsAuthenticated [as 別名]
def get_permissions(self):
        if self.action == 'image':
            permission_classes = ()
        elif self.action in ('list', 'retrieve', 'conversation'):
            permission_classes = (IsAuthenticated, )
        else:
            permission_classes = (IsAuthenticated, IsOfferUser)
        return [permission() for permission in permission_classes] 
開發者ID:yunity,項目名稱:karrot-backend,代碼行數:10,代碼來源:api.py

示例11: get_permissions

# 需要導入模塊: from rest_framework import permissions [as 別名]
# 或者: from rest_framework.permissions import IsAuthenticated [as 別名]
def get_permissions(self):

        if self.request.method in permissions.SAFE_METHODS:
            return (permissions.IsAuthenticated(),)

        if self.request.method == 'POST':
            return (permissions.AllowAny(),)

        return (permissions.IsAuthenticated(), IsAccountOwner(),) 
開發者ID:dkarchmer,項目名稱:django-aws-template,代碼行數:11,代碼來源:api_views.py

示例12: get_permissions

# 需要導入模塊: from rest_framework import permissions [as 別名]
# 或者: from rest_framework.permissions import IsAuthenticated [as 別名]
def get_permissions(self):
        """
        Instantiates and returns the list of permissions that this view requires.
        """
        if self.action == "create":
            # Allow any user to create an account, but limit other actions to logged-in users.
            permission_classes = [AllowAny]
        else:
            permission_classes = [IsAuthenticated]
        return [permission() for permission in permission_classes] 
開發者ID:open-craft,項目名稱:opencraft,代碼行數:12,代碼來源:views.py

示例13: get_permissions

# 需要導入模塊: from rest_framework import permissions [as 別名]
# 或者: from rest_framework.permissions import IsAuthenticated [as 別名]
def get_permissions(self):
        if self.action == 'create':
            return []
        elif self.action == 'update':
            return [permissions.IsAuthenticated()]
        return [permissions.IsAuthenticated()] 
開發者ID:xuchaoa,項目名稱:CTF_AWD_Platform,代碼行數:8,代碼來源:views.py

示例14: as_view

# 需要導入模塊: from rest_framework import permissions [as 別名]
# 或者: from rest_framework.permissions import IsAuthenticated [as 別名]
def as_view(cls, *args, **kwargs):
        view = super(AuthenticatedGraphQLView, cls).as_view(*args, **kwargs)
        view = permission_classes((IsAuthenticated,))(view)
        view = authentication_classes(api_settings.DEFAULT_AUTHENTICATION_CLASSES)(view)
        view = throttle_classes(api_settings.DEFAULT_THROTTLE_CLASSES)(view)
        view = api_view(["GET", "POST"])(view)
        view = csrf_exempt(view)

        return view 
開發者ID:eamigo86,項目名稱:graphene-django-extras,代碼行數:11,代碼來源:views.py

示例15: get_permissions

# 需要導入模塊: from rest_framework import permissions [as 別名]
# 或者: from rest_framework.permissions import IsAuthenticated [as 別名]
def get_permissions(self):
        """Define custom permissions for different methods"""

        # at minimum require users to be authenticated
        self.permission_classes = [IsAuthenticated]
        # for PUT requests require users to be admins
        if self.request.method == 'PUT':
            self.permission_classes.append(IsAdminUser)

        return super(viewsets.ViewSet, self).get_permissions() 
開發者ID:BrewCenter,項目名稱:BrewCenterAPI,代碼行數:12,代碼來源:fermentables.py


注:本文中的rest_framework.permissions.IsAuthenticated方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。