Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: drop use of deprecated allauth.utils.email_address_exists function #544

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions dj_rest_auth/registration/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.')

Expand Down Expand Up @@ -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 self._email_address_exists(email):
raise serializers.ValidationError(
_('A user is already registered with this e-mail address.'),
)
Expand Down Expand Up @@ -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)
Expand Down