Skip to content

Commit

Permalink
Merge ed03e56 into 624ad01
Browse files Browse the repository at this point in the history
  • Loading branch information
spuetz committed Feb 19, 2020
2 parents 624ad01 + ed03e56 commit 3595f49
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion rest_auth/serializers.py
Expand Up @@ -104,8 +104,15 @@ def validate(self, attrs):
# If required, is the email verified?
if 'rest_auth.registration' in settings.INSTALLED_APPS:
from allauth.account import app_settings
from allauth.account.models import EmailAddress
if app_settings.EMAIL_VERIFICATION == app_settings.EmailVerificationMethod.MANDATORY:
email_address = user.emailaddress_set.get(email=user.email)
try:
email_address = user.emailaddress_set.get(email=user.email)
# There is no corresponding email address object for the EmailAddress model, this could happen
# if the rest_auth app has bee installed after some users had already been created.
except EmailAddress.DoesNotExist:
email_address = EmailAddress(email=user.email, verified=True, primary=True)
email_address.save()
if not email_address.verified:
raise serializers.ValidationError(_('E-mail is not verified.'))

Expand Down

0 comments on commit 3595f49

Please sign in to comment.