django-allauth: cómo usar correctamente la señal email_confirmed para configurar el usuario como activo
Enotra publicación, Mencioné que estaba tratando de usar la señal de correo electrónico confirmado de allauth para cambiar el campo is_active en el usuario confirmado a verdadero. Sin embargo, el siguiente código me dio la excepción "La consulta de coincidencia de usuario no existe".
from allauth.account.signals import email_confirmed
from django.dispatch import receiver
from django.contrib.auth.models import User
@receiver(email_confirmed)
def email_confirmed_(request, email_address, **kwargs):
user = User.objects.get(email=email_address)
user.is_active = True
user.save()
Intenté volver a trabajar esto, y aún obtuve una excepción similar, "La consulta de coincidencia de dirección de correo electrónico no existe".
from allauth.account.signals import email_confirmed
from django.dispatch import receiver
from django.contrib.auth.models import User
from allauth.account.models import EmailAddress
@receiver(email_confirmed)
def email_confirmed_(request, email_address, **kwargs):
new_email_address = EmailAddress.objects.get(email=email_address)
user = User.objects.get(new_email_address.user)
user.is_active = True
user.save()
Traceback está aquí:
Environment:
Request Method: POST
Request URL: http://www.website.com/accounts/confirm-email/5901011619071fce757447ba146fe6312cb27bc0fee34d29665b857b479b49fc/
Django Version: 1.6.1
Python Version: 3.3.2
Installed Applications:
('django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'surveys',
'registration',
'django.contrib.sites',
'bootstrap3',
'allauth',
'allauth.account',
'allauth.socialaccount')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware')
Traceback:
File "/usr/local/lib/python3.3/dist-packages/django/core/handlers/base.py" in get_response
114. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/usr/local/lib/python3.3/dist-packages/django/views/generic/base.py" in view
69. return self.dispatch(request, *args, **kwargs)
File "/usr/local/lib/python3.3/dist-packages/django/views/generic/base.py" in dispatch
87. return handler(request, *args, **kwargs)
File "/usr/local/lib/python3.3/dist-packages/allauth/account/views.py" in post
204. confirmation.confirm(self.request)
File "/usr/local/lib/python3.3/dist-packages/allauth/account/models.py" in confirm
111. email_address=email_address)
File "/usr/local/lib/python3.3/dist-packages/django/dispatch/dispatcher.py" in send
185. response = receiver(signal=self, sender=sender, **named)
File "/home/username/website/webapp/mysite/views.py" in email_confirmed_
84. new_email_address = EmailAddress.objects.get(email=email_address)
File "/usr/local/lib/python3.3/dist-packages/django/db/models/manager.py" in get
151. return self.get_queryset().get(*args, **kwargs)
File "/usr/local/lib/python3.3/dist-packages/django/db/models/query.py" in get
307. self.model._meta.object_name)
Exception Type: DoesNotExist at /accounts/confirm-email/5901011619071fce757447ba146fe6312cb27bc0fee34d29665b857b479b49fc/
Exception Value: EmailAddress matching query does not exist.
Esto es confuso para mí, porque puedo verificar el campo de dirección de correo electrónico tanto en la tabla de usuario como en la tabla de "direcciones de correo electrónico" en mi base de datos y ambos parecen tener direcciones de correo electrónico coincidentes. Ayuda sería apreciada!