fix: email validation to remove unnecessary verification check#680
Open
Mohmmde1 wants to merge 2 commits into
Open
fix: email validation to remove unnecessary verification check#680Mohmmde1 wants to merge 2 commits into
Mohmmde1 wants to merge 2 commits into
Conversation
be05ee3 to
56deb39
Compare
- Remove unnecessary verification check. - Allow registration with unverified email when verification is not mandatory. - Prevent unique constraint errors by handling unverified emails properly. Updated the `validate_email` method in `CustomRegisterSerializer` to: - Allow registration if the email exists but is unverified, **only if verification is not mandatory**. - Prevent duplicate registrations if the email is already verified. - Improve error messages for better clarity. This ensures smoother registration flows while maintaining email uniqueness where required.
56deb39 to
9e44117
Compare
|
@iMerica any update on this? |
iMerica
approved these changes
Mar 7, 2025
| ) | ||
| raise serializers.ValidationError( | ||
| _('A user is already registered with this e-mail address.'), | ||
| _('A user is already registered with this email address.') |
Contributor
There was a problem hiding this comment.
Great change but change in this message from e-mail to email will break the existing translations.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull Request Description
Issue Summary
The current behavior of
dj-rest-authraises a database-level unique constraint error when a user tries to register using an email that already exists but is not verified, especially whenEMAIL_VERIFICATIONis set to MANDATORY.Why does this happen?
RegisterSerializerchecks for email uniqueness but does not properly handle unverified emails.user.save()is called, Django raises an IntegrityError due to the unique constraint on the email field in the User model.Error Example
If a user attempts to register with an existing, unverified email, the system throws this error:
This results in unexpected registration failures instead of properly informing the user about the issue.
Proposed Solution
Instead of allowing the process to reach
user.save()and fail due to the IntegrityError, we handle it earlier invalidate_email().EMAIL_VERIFICATIONis MANDATORY, we prevent registration with an appropriate message.EMAIL_VERIFICATIONis not mandatory, we allow registration to proceed.Updated Code Implementation
Why This Fix Works?
user.save().EMAIL_VERIFICATIONsetting, ensuring correct behavior based on project requirements.This update ensures that users understand why they cannot register with a certain email and avoids unexpected system errors.