Question

I am using django-allauth to handle user registration in my site. I noticed a strange behavior. Let's say I register a new user in the site. That user get's a new email with a link to click. When the user clicks that link it takes him in the confirm page. There the user clicks the confirm button and users email is confirmed.

The problem is that as as a side effect the user is also logged in. I don't want that. This only happens only the first time I visit that page. If I visit that page again and confirms the email the user does not log in automatically.

My question is how can I prevent the user log in even in the first time he confirms the email. I searched the documentation but couldn't not find any setting to prevent this. Also I looked in the source code of ConfirmEmailView and I can't see a way to turn off this behavior besides manually commenting this line

resp = self.login_on_confirm(confirmation)

Update:

I think I found a workaround to the problem without having to fork or whatever. I just copied that class in my own views file trying to make sure I also imported all the other dependencies that are needed. Then I just deleted that call on login and the function that it calls. I hope I did a good job with that. After that in my urls.py, right before the imports for allauth, I copied the line that is used for confirm-email and redirected it to my own view. And now it looks like this

url(r'^accounts/confirm-email/(?P<key>\w+)/$', 'userprofile.views.confirm_email',
                       name="account_confirm_email"),

Seems a bit hackish but it seems to work well. I hope someone comes up with a better solution.

Was it helpful?

Solution 2

looking at the ConfirmEmailView from here one can see that login is done only if LOGIN_ON_EMAIL_CONFIRMATION is true. In order to prevent login on email confirmation you should set LOGIN_ON_EMAIL_CONFIRMATION to False in settings.py.

OTHER TIPS

There is an option on the configuration ACCOUNT_LOGIN_ON_EMAIL_CONFIRMATION. It is True by default. Set it to False.

ACCOUNT_LOGIN_ON_EMAIL_CONFIRMATION = False
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top