当前位置: 首页>>代码示例>>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;未经允许,请勿转载。