From c923e54c49d56b72d246ec1c857e02e7c420b586 Mon Sep 17 00:00:00 2001 From: Alexei Date: Tue, 5 Sep 2023 13:16:36 +0100 Subject: [PATCH 1/2] fix: drop use of deprecated allauth.utils.email_address_exists function --- dj_rest_auth/registration/serializers.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dj_rest_auth/registration/serializers.py b/dj_rest_auth/registration/serializers.py index 003ed965..06659b13 100644 --- a/dj_rest_auth/registration/serializers.py +++ b/dj_rest_auth/registration/serializers.py @@ -13,9 +13,9 @@ from allauth.account.adapter import get_adapter from allauth.account.utils import setup_user_email from allauth.socialaccount.helpers import complete_social_login - from allauth.socialaccount.models import SocialAccount + from allauth.socialaccount.models import EmailAddress, SocialAccount from allauth.socialaccount.providers.base import AuthProcess - from allauth.utils import email_address_exists, get_username_max_length + from allauth.utils import get_username_max_length except ImportError: raise ImportError('allauth needs to be added to INSTALLED_APPS.') @@ -232,7 +232,7 @@ def validate_username(self, username): def validate_email(self, email): email = get_adapter().clean_email(email) if allauth_account_settings.UNIQUE_EMAIL: - if email and email_address_exists(email): + if email and EmailAddress.objects.is_verified(email): raise serializers.ValidationError( _('A user is already registered with this e-mail address.'), ) From 913070417a6566695b6279d4e78e415fe315ca05 Mon Sep 17 00:00:00 2001 From: Alexei Date: Tue, 5 Sep 2023 13:35:05 +0100 Subject: [PATCH 2/2] fix: use raw filter when EmailAddressManager.is_verified is not available --- dj_rest_auth/registration/serializers.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/dj_rest_auth/registration/serializers.py b/dj_rest_auth/registration/serializers.py index 06659b13..f2211e27 100644 --- a/dj_rest_auth/registration/serializers.py +++ b/dj_rest_auth/registration/serializers.py @@ -232,7 +232,7 @@ def validate_username(self, username): def validate_email(self, email): email = get_adapter().clean_email(email) if allauth_account_settings.UNIQUE_EMAIL: - if email and EmailAddress.objects.is_verified(email): + if email and self._email_address_exists(email): raise serializers.ValidationError( _('A user is already registered with this e-mail address.'), ) @@ -273,6 +273,15 @@ def save(self, request): setup_user_email(request, user, []) return user + def _email_address_exists(self, email): + # `EmailAddressManager.is_verified` was introduced in django-allauth==0.55.2 + # so if it's not available we're filtering the queryset ourselves; + try: + retval = EmailAddress.objects.is_verified(email) + except AttributeError: + retval = EmailAddress.objects.filter(email__iexact=email, verified=True).exists() + return retval + class VerifyEmailSerializer(serializers.Serializer): key = serializers.CharField(write_only=True)