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

Corner case handling for non existing email address #601

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
9 changes: 8 additions & 1 deletion rest_auth/serializers.py
Original file line number Diff line number Diff line change
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(user=user, 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