sunscrapers / djoser

REST implementation of Django authentication system.
MIT License
2.55k stars 458 forks source link

Users keep getting repeated Activation Emails even though they are already active #624

Open rob4226 opened 3 years ago

rob4226 commented 3 years ago

Hi,

I am using Djoser with the SimpleJWT plugin and for some reason my users get constant user Activation emails from my server even after they have activated in the past. If they click on the activation link again it just says they have already activated.

Does it have something to do with updating a User that triggers this email again? I would think the only time an activation email should be sent out is when a user is created and is not active. Any ideas on why this would be happening? Thanks!

Djoser settings:

DJOSER = {
    'PASSWORD_RESET_CONFIRM_URL': 'users/reset-password/{uid}/{token}',
    'USERNAME_RESET_CONFIRM_URL': 'users/reset-username/confirm/{uid}/{token}',
    'ACTIVATION_URL': 'users/activate/{uid}/{token}',
    'SEND_ACTIVATION_EMAIL': True,
    'PASSWORD_CHANGED_EMAIL_CONFIRMATION': True,
    'USER_CREATE_PASSWORD_RETYPE': True,
    'SET_PASSWORD_RETYPE': True,
    'TOKEN_MODEL': None,
    'SERIALIZERS': {
        'user': 'restapi.serializers.CustomUserSerializer',
        'current_user': 'restapi.serializers.CustomUserSerializer',
    },
}
rob4226 commented 3 years ago

Never mind, I see it was fixed in commit 2b3357b 8 months ago with the below:

https://github.com/sunscrapers/djoser/blob/b648b07dc2da7dab4c00c1c39af3d6ec53f58eb6/djoser/views.py#L148-L155

But the djoser package on PyPi is outdated and has:

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)

I just installed from the git repo instead, so that should take care of it:

pipenv install git+https://github.com/sunscrapers/djoser.git#egg=djoser
DBlek commented 2 years ago

After changes introduced by @dekoza 4 days ago, it is impossible to install djoser using the git+https://github.com/sunscrapers/djoser.git#egg=djoser and on pypi the problem still persists with the activation emails...

Upon installing i get the error that I wrote the comment about https://github.com/sunscrapers/djoser/commit/c62371e3f9a8bbad2eaf55ffd0efad6eb6c02f26#r64007511

rob4226 commented 2 years ago

Thanks for the heads up.

Is there any reason the pypi package doesn't get updated? Last release is from Oct-2020.

DBlek commented 2 years ago

dunno - Need to ask maintainers about this ASAP @dekoza is the first that comes to mind

rob4226 commented 2 years ago

I checked my pipenv lock file on a production site and found I have been using commit b648b07dc2da7dab4c00c1c39af3d6ec53f58eb6 so I changed the install url to https://github.com/sunscrapers/djoser.git@b648b07dc2da7dab4c00c1c39af3d6ec53f58eb6 which got my virtual env install working again until hopefully the PyPi package gets updated.

DBlek commented 2 years ago

@rob4226 well I can't update using your link ~~but git+https://github.com/sunscrapers/djoser.git@aa056350c8444a073666cce9291f7fcfef62822a works for me

The commit you linked is not merged - you should use aa05635

EDIT:

Unfortunately commit aa05635 doesn't include the changes with activation e-mail so its safer to use ede06f2 I think - just before @dekoza introduced the poetry changes

rob4226 commented 2 years ago

Are you sure? It looks like b648b07 is merged but yeah it would prob be better anyway to use the latest commit before the poetry thing. I'll try ede06f2

DBlek commented 2 years ago

For me b648b07 caused the same error...