Skip to content

Commit be05ee3

Browse files
committed
fix: prevent unique constraint error by handling unverified emails
1 parent 812b89e commit be05ee3

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

dj_rest_auth/registration/serializers.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -237,18 +237,20 @@ def validate_username(self, username):
237237

238238
def validate_email(self, email):
239239
email = get_adapter().clean_email(email)
240+
240241
if allauth_account_settings.UNIQUE_EMAIL:
241242
existing_email = EmailAddress.objects.filter(email=email).first()
243+
242244
if existing_email:
243-
if existing_email.verified:
244-
raise serializers.ValidationError(
245-
"A user is already registered with this email address."
246-
)
247-
elif allauth_account_settings.EMAIL_VERIFICATION == \
245+
if not existing_email.verified and allauth_account_settings.EMAIL_VERIFICATION == \
248246
allauth_account_settings.EmailVerificationMethod.MANDATORY:
249247
raise serializers.ValidationError(
250248
"This email is already in use but has not been verified."
251249
)
250+
raise serializers.ValidationError(
251+
"A user is already registered with this email address."
252+
)
253+
252254
return email
253255

254256
def validate_password1(self, password):

0 commit comments

Comments
 (0)