Skip to content
This repository has been archived by the owner on May 26, 2020. It is now read-only.

Fix is_active error message #391

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
15 changes: 9 additions & 6 deletions rest_framework_jwt/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from django.contrib.auth import authenticate, get_user_model
from django.utils.translation import ugettext as _
from django.core.exceptions import ObjectDoesNotExist
from rest_framework import serializers
from .compat import Serializer

Expand Down Expand Up @@ -50,19 +51,21 @@ def validate(self, attrs):
user = authenticate(**credentials)

if user:
if not user.is_active:
msg = _('User account is disabled.')
raise serializers.ValidationError(msg)

payload = jwt_payload_handler(user)

return {
'token': jwt_encode_handler(payload),
'user': user
}
else:
msg = _('Unable to log in with provided credentials.')
raise serializers.ValidationError(msg)
try:
user = User.objects.get(**{self.username_field: attrs.get(self.username_field)})
if not user.is_active:
msg = _('User account is disabled.')
raise serializers.ValidationError(msg)
except ObjectDoesNotExist:
msg = _('Unable to log in with provided credentials.')
raise serializers.ValidationError(msg)
else:
msg = _('Must include "{username_field}" and "password".')
msg = msg.format(username_field=self.username_field)
Expand Down