From 6aba08ec82f2f9a7809775e7e0f8681191e1e2c8 Mon Sep 17 00:00:00 2001 From: Filippo Morelli Date: Mon, 28 Mar 2022 21:21:09 +0200 Subject: [PATCH] Handle login by users with no EmailAddress (#391) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 👍 --- dj_rest_auth/serializers.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/dj_rest_auth/serializers.py b/dj_rest_auth/serializers.py index 0fd83f32..e4284aff 100644 --- a/dj_rest_auth/serializers.py +++ b/dj_rest_auth/serializers.py @@ -108,10 +108,11 @@ def validate_auth_user_status(user): @staticmethod def validate_email_verification_status(user): from allauth.account import app_settings - if app_settings.EMAIL_VERIFICATION == app_settings.EmailVerificationMethod.MANDATORY: - email_address = user.emailaddress_set.get(email=user.email) - if not email_address.verified: - raise serializers.ValidationError(_('E-mail is not verified.')) + if ( + app_settings.EMAIL_VERIFICATION == app_settings.EmailVerificationMethod.MANDATORY + and not user.emailaddress_set.filter(email=user.email, verified=True).exists() + ): + raise serializers.ValidationError(_('E-mail is not verified.')) def validate(self, attrs): username = attrs.get('username')