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,
    ....
}
Xenetrix
  • 339
  • 2
  • 19
  • 3
    https://github.com/sunscrapers/djoser/issues/546#issuecomment-772146085 – iklinac Feb 09 '21 at 06:56
  • 3
    I made a [pull request](https://github.com/sunscrapers/djoser/pull/638#event-5845913084) 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. – AlirezaAsadi Jan 05 '22 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 – Mark McKeon Feb 05 '22 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: https://stackoverflow.com/questions/20101834/pip-install-from-git-repo-branch – AlirezaAsadi Feb 05 '22 at 12:26
  • 1
    @AlirezaAsadi Thanks for your prompt reply. I managed to work it out last night! – Mark McKeon Feb 05 '22 at 23:12

1 Answers1

-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)
Jurgen Strydom
  • 3,540
  • 1
  • 23
  • 30
Hemza Talha
  • 79
  • 1
  • 3