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

Error message if inactive account for email activation requirement #578

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

hussu010
Copy link

No description provided.

@jhill-cmd
Copy link

does it work?

@hussu010
Copy link
Author

hussu010 commented Mar 1, 2021

yeah, it does. there is an error message for inactive users in serializers.py inactive_account": settings.CONSTANTS.messages.INACTIVE_ACCOUNT_ERROR but it's not checking if the user is inactive here
You can check it in your codebase ^_^

@jhill-cmd
Copy link

jhill-cmd commented Mar 1, 2021

I have tested, but it doesn't looks like to work on my side but i might miss something.

What i did:

# in app/serializer.py
class CustomTokenCreateSerializer(TokenCreateSerializer):
    def validate(self, attrs):
        print("xxx")
        password = attrs.get("password")
        params = {djoser.conf.settings.LOGIN_FIELD: attrs.get(djoser.conf.settings.LOGIN_FIELD)}
        self.user = authenticate(
            request=self.context.get("request"), **params, password=password
        )
        if not self.user:
            self.user = User.objects.filter(**params).first()
            if self.user and not self.user.check_password(password):
                self.fail("invalid_credentials")
        if self.user and self.user.is_active:
            return attrs
        if self.user and not self.user.is_active:
            self.fail("inactive_account")
        self.fail("invalid_credentials")

# And in settings.py:
DJOSER = {
....
    'SERIALIZERS': {
       'token_create': 'app.serializers.CustomTokenCreateSerializer',
    },
}

REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': (
     'rest_framework_simplejwt.authentication.JWTAuthentication',
    ...
    ),
}

but i never see my print(). I guess i'm missing something.

@hussu010
Copy link
Author

hussu010 commented Mar 1, 2021

you'll need to write your custom views.py to use custom serializer and custom urls.py to use that custom views.py

@jhill-cmd
Copy link

I do not fully understand why.

       'token_create': 'app.serializers.CustomTokenCreateSerializer',

is not supposed to indicate which serializer to call ?

@hussu010
Copy link
Author

hussu010 commented Mar 4, 2021

are you using JWT for authentication?

@jhill-cmd
Copy link

Yes. I 've just posted my solution here #571
post

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