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

Commit

Permalink
Add PasswordField for compat
Browse files Browse the repository at this point in the history
  • Loading branch information
jpadilla committed Jul 26, 2015
1 parent eb20889 commit 5cdc62c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
12 changes: 10 additions & 2 deletions rest_framework_jwt/compat.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
import rest_framework

from django.forms import widgets
from distutils.version import StrictVersion


if StrictVersion(rest_framework.VERSION) < StrictVersion('3.0.0'):
from rest_framework.serializers import Serializer
from rest_framework.serializers import Serializer, CharField

class PasswordField(CharField):
widget = widgets.PasswordInput
else:
class Serializer(rest_framework.serializers.Serializer):
@property
def object(self):
return self.validated_data

class PasswordField(rest_framework.serializers.CharField):
style = {
'input_type': 'password'
}


def get_user_model():
try:
Expand Down
8 changes: 4 additions & 4 deletions rest_framework_jwt/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
from rest_framework import serializers
from .compat import Serializer

from rest_framework_jwt.compat import get_user_model, get_username_field
from rest_framework_jwt.settings import api_settings
from rest_framework_jwt.compat import (
get_user_model, get_username_field, PasswordField
)


User = get_user_model()
Expand All @@ -34,9 +36,7 @@ def __init__(self, *args, **kwargs):
super(JSONWebTokenSerializer, self).__init__(*args, **kwargs)

self.fields[self.username_field] = serializers.CharField()
self.fields['password'] = serializers.CharField(
style={'input_type': 'password'}
)
self.fields['password'] = PasswordField(write_only=True)

@property
def username_field(self):
Expand Down
3 changes: 1 addition & 2 deletions tests/test_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ def test_empty_drf2(self):
def test_empty_drf3(self):
serializer = JSONWebTokenSerializer()
expected = {
'username': '',
'password': '',
'username': ''
}

self.assertEqual(serializer.data, expected)
Expand Down

0 comments on commit 5cdc62c

Please sign in to comment.