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

Commit

Permalink
Code format tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
jpadilla committed Jan 24, 2015
1 parent 3cf5079 commit 5ac44c8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
11 changes: 8 additions & 3 deletions rest_framework_jwt/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ class JSONWebTokenSerializer(Serializer):
password = serializers.CharField(write_only=True)

def __init__(self, *args, **kwargs):
"""Dynamically add the USERNAME_FIELD to self.fields."""
"""
Dynamically add the USERNAME_FIELD to self.fields.
"""
super(JSONWebTokenSerializer, self).__init__(*args, **kwargs)
self.fields[self.username_field] = serializers.CharField()

Expand All @@ -44,8 +46,11 @@ def username_field(self):
return 'username'

def validate(self, attrs):
credentials = {self.username_field: attrs.get(self.username_field),
'password': attrs.get('password')}
credentials = {
self.username_field: attrs.get(self.username_field),
'password': attrs.get('password')
}

if all(credentials.values()):
user = authenticate(**credentials)

Expand Down
6 changes: 6 additions & 0 deletions rest_framework_jwt/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@ class ObtainJSONWebToken(APIView):

def post(self, request):
serializer = self.serializer_class(data=request.DATA)

if serializer.is_valid():
user = serializer.object.get('user') or request.user
token = serializer.object.get('token')
response_data = jwt_response_payload_handler(token, user)

return Response(response_data)

return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)


Expand All @@ -51,11 +54,14 @@ class RefreshJSONWebToken(APIView):

def post(self, request):
serializer = self.serializer_class(data=request.DATA)

if serializer.is_valid():
user = serializer.object.get('user') or request.user
token = serializer.object.get('token')
response_data = jwt_response_payload_handler(token, user)

return Response(response_data)

return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)


Expand Down

0 comments on commit 5ac44c8

Please sign in to comment.