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

Support custom verification status based on email #504

Merged
merged 1 commit into from
May 7, 2023
Merged

Support custom verification status based on email #504

merged 1 commit into from
May 7, 2023

Conversation

c-w
Copy link
Contributor

@c-w c-w commented Apr 27, 2023

What does this change do?

This pull request extends the interface of LoginSerializer.validate_email_verification_status to pass-through the email value that's used for the current login. This interface change enables us to customize the logic to check the verification status in subclasses without needing to override the full validate method, thus reducing coupling between subclasses and the parent.

Why is this useful?

I'm working on a system where the user is allowed to change their email but they need to verify their new email before they can use it to log in. Currently, dj-rest-auth will allow the user to log in with their new email address even before it's verified as the code is checking that the user has any verified email address. I want to customize this behavior by subclassing to check that the specific email address the user is logging in with is verified:

class MyLoginSerializer(LoginSerializer):
    @staticmethod
    def validate_email_verification_status(user, email=None):
        if not user.emailaddress_set.filter(email=email, verified=True).exists():
            raise serializers.ValidationError(_('E-mail is not verified.'))

Arguably dj-rest-auth could even make this check the default behavior as it seems semantically correct, but this would be a backwards incompatible change which is why I propose the change in this PR to simply extend the interface of the validation function.

Copy link

@salmanmorshed salmanmorshed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@iMerica iMerica merged commit 50f2a9c into iMerica:master May 7, 2023
@c-w c-w deleted the login-email-status branch May 8, 2023 06:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants