Example #1
0
 def _action(self, serializer):
     token = utils.login_user(self.request, serializer.user)
     token_serializer_class = djoser_conf.settings.SERIALIZERS.token
     return response(
         content=token_serializer_class(token).data,
         status=status.HTTP_200_OK,
     )
Example #2
0
    def _action(self, serializer):
        self.request.user.set_password(serializer.data['new_password'])
        self.request.user.save()

        if djoser_conf.settings.LOGOUT_ON_PASSWORD_CHANGE:
            utils.logout_user(self.request)

        return response(status=status.HTTP_204_NO_CONTENT)
Example #3
0
    def post(self, request, *args, **kwargs):
        instance = self.get_object()
        serializer = self.get_serializer(instance, data=request.data)
        serializer.is_valid(raise_exception=True)

        utils.logout_user(self.request)
        instance.delete()

        return response(status=status.HTTP_204_NO_CONTENT)
Example #4
0
    def list(self, request, *args, **kwargs):
        queryset = self.filter_queryset(self.get_queryset())

        page = self.paginate_queryset(queryset)
        if page is not None:
            serializer = self.get_serializer(page, many=True)
            return self.get_paginated_response(serializer.data)
        serializer = self.get_serializer(queryset, many=True)
        return response(serializer.data, status.HTTP_200_OK)
Example #5
0
    def retrieve(self, request, *args, **kwargs):
        instance = self.get_object()

        context = {'user': instance}
        to = [get_user_email(instance)]
        if djoser_conf.settings.SEND_ACTIVATION_EMAIL:
            djoser_conf.settings.EMAIL.activation(self.request,
                                                  context).send(to)

        return response(status=status.HTTP_200_OK)
Example #6
0
 def _action(self, serializer):
     token = utils.login_user(self.request, serializer.user)
     token_serializer_class = djoser_conf.settings.SERIALIZERS.token
     return response(content={
         'token':
         token_serializer_class(token).data['auth_token'],
         'is_active':
         serializer.user.is_active
     },
                     status=status.HTTP_200_OK)
Example #7
0
    def _action(self, serializer):
        user = self.request.user
        new_username = serializer.data['new_' + User.USERNAME_FIELD]

        setattr(user, User.USERNAME_FIELD, new_username)
        if djoser_conf.settings.SEND_ACTIVATION_EMAIL:
            user.is_active = False
            context = {'user': user}
            to = [djoser.compat.get_user_email(user)]
            djoser_conf.settings.EMAIL.activation(self.request, context).send(to)
        user.save()

        return response(status=status.HTTP_204_NO_CONTENT)
Example #8
0
    def update(self, request, *args, **kwargs):
        partial = kwargs.pop('partial', False)
        instance = self.get_object()
        serializer = self.get_serializer(instance, data=request.data, partial=partial)
        serializer.is_valid(raise_exception=True)
        self.perform_update(serializer)

        if getattr(instance, '_prefetched_objects_cache', None):
            # If 'prefetch_related' has been applied to a queryset, we need to
            # forcibly invalidate the prefetch cache on the instance.
            instance._prefetched_objects_cache = {}

        return response(content=serializer.data, status=status.HTTP_200_OK)
Example #9
0
    def _action(self, serializer):
        user = serializer.user
        user.is_active = True
        user.save()

        signals.user_activated.send(
            sender=self.__class__, user=user, request=self.request
        )

        if djoser_conf.settings.SEND_CONFIRMATION_EMAIL:
            context = {'user': user}
            to = [djoser.compat.get_user_email(user)]
            djoser_conf.settings.EMAIL.confirmation(self.request, context).send(to)

        return response(status=status.HTTP_204_NO_CONTENT)
Example #10
0
 def _action(self, serializer):
     for user in self.get_users(serializer.data['email']):
         self.send_password_reset_email(user)
     return response(status=status.HTTP_204_NO_CONTENT)
Example #11
0
 def post(self, request):
     utils.logout_user(request)
     return response(status=status.HTTP_204_NO_CONTENT)
Example #12
0
 def retrieve(self, request, *args, **kwargs):
     instance = self.get_object()
     serializer = self.get_serializer(instance)
     return response(content=serializer.data, status=status.HTTP_200_OK)
Example #13
0
 def _action(self, serializer):
     serializer.user.set_password(serializer.data['new_password'])
     serializer.user.save()
     return response(status=status.HTTP_204_NO_CONTENT)
Example #14
0
 def destroy(self, request, *args, **kwargs):
     instance = self.get_object()
     self.perform_destroy(instance)
     return response({}, status.HTTP_204_NO_CONTENT)
Example #15
0
 def create(self, request, *args, **kwargs):
     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.HTTP_201_CREATED)