How can I treat allauth password reset as email verification?

Viewed 239

My system is already aware of the users' email addresses. When a user signs up, they get an error message from allauth:

A user is already registered with this e-mail address.

I advise users to reset their password when they see this message. However, once they've reset their password, allauth triggers the email address confirmation flow, since ACCOUNT_EMAIL_VERIFICATION = True.

It is inconvenient and unneccessary for the user to also do email validation at this point. How can I avoid email verification in this scenario?

1 Answers

If you know that the user can only ever have one email address associated with them at the point of the password reset, then you can listen for the password reset signal and mark the email address verified. This will prevent allauth from triggering the email verification flow after the password reset.

For example, you can put the following within signals.py:

from django.dispatch import receiver
from allauth.account.models import EmailAddress
from allauth.account.signals import password_reset


@receiver(password_reset)
def auto_verify_email_address_on_password_reset(sender, request, user, **kwargs):
    email_address = EmailAddress.objects.get_for_user(user, user.email)
    if not email_address.verified:
        email_address.verified = True
        email_address.save()
Related