Exemplo n.º 1
0
    def _action(self, serializer):
        self.request.user.set_password(serializer.data['new_password'])
        self.request.user.save()

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

        return Response(status=status.HTTP_204_NO_CONTENT)
Exemplo n.º 2
0
    def _action(self, serializer):
        self.request.user.set_password(serializer.data['new_password'])
        self.request.user.save()

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

        return Response(status=status.HTTP_204_NO_CONTENT)
Exemplo n.º 3
0
    def destroy(self, request, *args, **kwargs):
        instance = self.get_object()
        serializer = self.get_serializer(instance, data=request.data)
        serializer.is_valid(raise_exception=True)

        if instance == request.user:
            utils.logout_user(self.request)
        self.perform_destroy(instance)
        return Response(status=status.HTTP_204_NO_CONTENT)
Exemplo n.º 4
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)
Exemplo n.º 5
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)
Exemplo n.º 6
0
 def post(self, request):
     utils.logout_user(request)
     return Response(
         {
             'message': 'User logout successfully',
             'success': True,
             'status': status.HTTP_200_OK,
             'data': []
         },
         status=status.HTTP_200_OK)
Exemplo n.º 7
0
    def _action(self, serializer):
        self.request.user.set_password(serializer.data['new_password'])
        self.request.user.save()
        with translation.override(LANGUAGES_LIST[self.request.user.preferred_language - 1]):
            send_mail(_("Password changed"),
                      _(
                          "Your password has been changed. If it happened without your desire - contact us by email [email protected]."),
                      'noreply@' + settings.DOMAIN, [self.request.user.email])
        if djoser_settings.LOGOUT_ON_PASSWORD_CHANGE:
            logout_user(self.request)

        return Response(status=status.HTTP_204_NO_CONTENT)
Exemplo n.º 8
0
    def _action(self, serializer):
        user = self.request.user
        user_serializer = self.get_serializer(user, serializer.data)

        if user_serializer.is_valid():
            user_serializer.save()
            if settings.SEND_ACTIVATION_EMAIL:
                user.is_active = False
                context = {'user': user}
                recipient = [get_user_email(user)]
                mailer.ActivationEmail(self.request, context, recipient).send()

            utils.logout_user(self.request)
            return Response(status=status.HTTP_204_NO_CONTENT)
        return Response(user_serializer.errors, status.HTTP_400_BAD_REQUEST)
Exemplo n.º 9
0
    def set_password(self, request, *args, **kwargs):
        serializer = self.get_serializer(data=request.data)
        serializer.is_valid(raise_exception=True)

        self.request.user.set_password(serializer.data["new_password"])
        self.request.user.save()

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

        if settings.PASSWORD_CHANGED_EMAIL_CONFIRMATION:
            context = {"user": self.request.user}
            to = [get_user_email(self.request.user)]
            settings.EMAIL.password_changed_confirmation(self.request, context).send(to)
        return Response(status=status.HTTP_204_NO_CONTENT)
Exemplo n.º 10
0
 def post(self, request):
     utils.logout_user(request)
     return Response(status=status.HTTP_204_NO_CONTENT)
Exemplo n.º 11
0
 def perform_destroy(self, instance):
     utils.logout_user(self.request)
     super(UserViewSet, self).perform_destroy(instance)
Exemplo n.º 12
0
 def perform_destroy(self, instance):
     utils.logout_user(self.request)
     super(UserViewSet, self).perform_destroy(instance)
Exemplo n.º 13
0
 def post(self, request):
     utils.logout_user(request)
     return Response(status=status.HTTP_204_NO_CONTENT)
Exemplo n.º 14
0
 def _action(self, serializer):
     serializer.user.set_password(serializer.data['new_password'])
     serializer.user.save()
     if self.request.user.is_authenticated:
         utils.logout_user(self.request)
     return Response(status=status.HTTP_204_NO_CONTENT)
Exemplo n.º 15
0
 def delete(request):
     utils.logout_user(request)
     return Response(status=status.HTTP_204_NO_CONTENT)