django-allauth: how to properly use email_confirmed signal to set user to active
Turns out the email_address returned by the email_confirmed signal isn't actually a string containing the address, but an object -- allauth.account.models.EmailAddress. This wasn't very clear at all from the documentation, but glad it's resolved now. The code that ended up working was:
@receiver(email_confirmed)
def email_confirmed_(request, email_address, **kwargs):
user = User.objects.get(email=email_address.email)
user.is_active = True
user.save()
I found this page while trying to set up a signal from AllAuth to my CustomUser Model.
After some debugging and continued searching, I found an old GitHub thread on the subject: https://github.com/pennersr/django-allauth/issues/347. His solution worked for me.
I changed the location of my receiver function from app/signals.py to app/models.py
Apparently, by default the ready() function of the AppConfig Class imports the models.py file, but a signals.py file needs to be manually added to your apps.py file:
from django.apps import AppConfig
class NameOfAppConfig(AppConfig):
name = 'NameOfApp'
def ready(self):
import NameOfApp.signals
Anyway, it's easy to miss this in the documentation. I'd guess in future Django releases they will include a signals.py file as a default file and incorporate it automatically.