Merge pull request #286 from Tivix/jwt-serializer-with-custom-user-model

JWT serializer with custom user model
This commit is contained in:
Maxim Kukhtenkov 2016-12-09 10:12:52 -05:00 committed by GitHub
commit d20a601fdd

View File

@ -6,11 +6,12 @@ from django.utils.http import urlsafe_base64_decode as uid_decoder
from django.utils.translation import ugettext_lazy as _
from django.utils.encoding import force_text
from .models import TokenModel
from rest_framework import serializers, exceptions
from rest_framework.exceptions import ValidationError
from .models import TokenModel
from .utils import import_callable
# Get the UserModel
UserModel = get_user_model()
@ -130,12 +131,20 @@ class UserDetailsSerializer(serializers.ModelSerializer):
read_only_fields = ('email', )
# Required to allow using custom USER_DETAILS_SERIALIZER in
# JWTSerializer. Defining it here to avoid circular imports
rest_auth_serializers = getattr(settings, 'REST_AUTH_SERIALIZERS', {})
JWTUserDetailsSerializer = import_callable(
rest_auth_serializers.get('USER_DETAILS_SERIALIZER', UserDetailsSerializer)
)
class JWTSerializer(serializers.Serializer):
"""
Serializer for JWT authentication.
"""
token = serializers.CharField()
user = UserDetailsSerializer()
user = JWTUserDetailsSerializer()
class PasswordResetSerializer(serializers.Serializer):