4

Every time when I try to update my user with the PATCH method to the /users/me/ endpoint, an activation email is always sent. The user is already active in the system... so I don't know what is happening.

SEND_ACTIVATION_EMAIL is True, but I understand that the email will be sent only after: creating an account or updating their email (I'm not updating the email)

DJOSER = {
    ....
    'ACTIVATION_URL': 'auth/users/activation/{uid}/{token}',
    'SEND_ACTIVATION_EMAIL': True,
    ....
}
5
  • 3
  • 3
    I made a pull request and was merged with master code in djoser. This will fix the issue with patch or put requests to /auth/users/me/ endpoint and send activation email only when email is updated and is not the same as the previous email. Commented Jan 5, 2022 at 14:59
  • @AlirezaAsadi can you please help me. I have the same issue and Im not sure how to add this code into my serializers. Any help would be really appreciated Commented Feb 5, 2022 at 11:43
  • 1
    @MarkMcKeon You can check Files changed part in the pull request and make the same changes in your project OR you can directly install djoser from its master branch to get the latest version (which has activation email fixed). Here is a question that may help: stackoverflow.com/questions/20101834/… Commented Feb 5, 2022 at 12:26
  • 1
    @AlirezaAsadi Thanks for your prompt reply. I managed to work it out last night! Commented Feb 5, 2022 at 23:12

1 Answer 1

-1

I have the same issue. This is due to the djoser.views.UserViewSet.perform_update method.

    def perform_update(self, serializer):
    super().perform_update(serializer)
    user = serializer.instance
    #should we send activation email after update?
    if settings.SEND_ACTIVATION_EMAIL:
        context = {"user": user}
        to = [get_user_email(user)]
        settings.EMAIL.activation(self.request, context).send(to)

As you can see, even if you use email as a login field, you keep getting email confirmation if you update any field. This is not the right thing to do. This should be done only if the email has changed.

In your case the update part should be omitted:

#user = serializer.instance
#should we send activation email after update?    
#if settings.SEND_ACTIVATION_EMAIL:
        #context = {"user": user}
        #to = [get_user_email(user)]
        #settings.EMAIL.activation(self.request, context).send(to)
1
  • Why did you comment out all the code?
    – Seif
    Commented Apr 17, 2022 at 11:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.