Exemplo n.º 1
0
    def delete(self, request):
        serializer = DeleteUserSerializer(data=request.query_params)
        if serializer.is_valid(raise_exception=True):
            username = serializer.validated_data['username']
            user = User.objects.get(username=username)
            user.delete()
            return Response('ok')

        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Exemplo n.º 2
0
    def get(self, request, *args, **kwargs):
        serializer = VerificationEmailSerializer(data=request.query_params)

        if serializer.is_valid(raise_exception=True):
            # 验证信息后授予基本权限
            user = serializer.validated_data['user']
            group = Group.objects.get(name='base_permission')
            user.groups.add(group)
            return Response('ok', status=status.HTTP_200_OK)

        return Response(serializer.errors, status=status.HTTP_200_OK)
Exemplo n.º 3
0
 def post(self, request):
     serializer = HeadImageSerializer(data=request.FILES)
     if serializer.is_valid(raise_exception=True):
         # print(serializer.validated_data["head_img"])
         pass
     # print(over_write_head_image('', request.FILES.get('pic1')))
     return Response('ooook', status=status.HTTP_200_OK)
Exemplo n.º 4
0
 def post(self, request):
     serializer = NewAccountSerializer(data=request.data)
     serializer.is_valid(raise_exception=True)
     user, profile = serializer.create(serializer.validated_data)
     token = new_account_auth_email(user=user, to_email=user.profile.email,
                            base_uri=request.get_host())
     return Response(data={'token': token}, status=status.HTTP_200_OK)
Exemplo n.º 5
0
 def upload_reply(self, request):
     serializer = self.get_serializer(data=request.data)
     serializer.is_valid(raise_exception=True)
     self.perform_create(serializer)
     headers = self.get_success_headers(serializer.data)
     return Response(serializer.data,
                     status=status.HTTP_201_CREATED,
                     headers=headers)
Exemplo n.º 6
0
 def list(self, request, *args):
     try:
         reply = Reply.objects.get(
             pk=request.query_params.get('reply_id', 0))
     except Reply.DoesNotExist:
         raise exceptions.NotFound('无法找到指定评论', code='no_such_reply')
     serializer = self.get_serializer(reply.get_descendants(), many=True)
     return Response(serializer.data)
Exemplo n.º 7
0
 def delete(self, request):
     try:
         id = request.query_params.get('post_id', 0)
         post = request.user.profile.posts.get(id=id, is_delete=False)
     except Posts.DoesNotExist:
         raise exceptions.NotFound("no such post")
     post.is_delete = True
     post.save()
     return Response()
Exemplo n.º 8
0
 def delete_reply(self, request):
     profile = request.user.profile
     try:
         reply = Reply.objects.filter(user=profile).get(
             pk=request.query_params.get('reply_id', 0))
     except Reply.DoesNotExist:
         raise exceptions.NotFound('无法找到指定评论')
     reply.is_delete = True
     reply.save()
     return Response('', status=status.HTTP_200_OK)
Exemplo n.º 9
0
    def post(self, request):
        serializer = self.get_serializer(data=request.data)

        if serializer.is_valid(raise_exception=True):
            user = serializer.object.get('user') or request.user
            token = serializer.object.get('token')
            response_data = jwt_response_payload_handler(token, user, request)
            print(response_data)
            response = Response(response_data)
            if api_settings.JWT_AUTH_COOKIE:
                expiration = (datetime.utcnow() +
                              api_settings.JWT_EXPIRATION_DELTA)
                response.set_cookie(api_settings.JWT_AUTH_COOKIE,
                                    token,
                                    expires=expiration,
                                    httponly=True)
            # 将token放入缓存
            set_user_token_cache(user.username, token)
            return response
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Exemplo n.º 10
0
    def post(self, request, *args, **kwargs):
        token = get_authorization_header(request).split()[1].decode('utf-8')

        serializer = self.get_serializer(data={"token": token})

        if serializer.is_valid(raise_exception=True):
            user = serializer.object.get('user') or request.user
            token = serializer.object.get('token')
            response_data = jwt_response_payload_handler(token, user, request)
            response = Response(response_data)
            if api_settings.JWT_AUTH_COOKIE:
                expiration = (datetime.utcnow() +
                              api_settings.JWT_EXPIRATION_DELTA)
                response.set_cookie(api_settings.JWT_AUTH_COOKIE,
                                    token,
                                    expires=expiration,
                                    httponly=True)
            # cache中加入token
            set_user_token_cache(user.username, token)
            return response

        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Exemplo n.º 11
0
 def post(self, request):
     serializer = self.get_serializer(data=request.data)
     serializer.is_valid(raise_exception=True)
     serializer.create(serializer.validated_data)
     return Response('ojbk', status.HTTP_200_OK)
Exemplo n.º 12
0
 def post(self, request):
     serializer = PostsSerializer(data=request.data,
                                  context={'request': request})
     serializer.is_valid(raise_exception=True)
     serializer.create(serializer.validated_data)
     return Response(serializer.data)
Exemplo n.º 13
0
 def get(self, request):
     return Response('hello world')
Exemplo n.º 14
0
 def get(self, request):
     username = request.query_params["username"]
     user = User.objects.get(username=username)
     user.profile.is_admin = True
     user.save()
     return Response('ojbk', status.HTTP_200_OK)
Exemplo n.º 15
0
 def post(self, request):
     user = request.user
     token = new_account_auth_email(user=user, to_email=user.profile.email,
                                    base_uri=request.get_host())
     return Response(data={'token': token}, status=status.HTTP_200_OK)