Skip to content

Commit

Permalink
Merge pull request #151 from James1345/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
belugame authored Dec 31, 2018
2 parents f77752b + f832100 commit c1972fc
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
3.6.0
=====

- The user serializer for each `LoginView`is now dynamic


3.5.0
=====

Expand Down
4 changes: 4 additions & 0 deletions docs/changes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 3.6.0

- The user serializer for each `LoginView`is now dynamic

## 3.5.0

- The context, token TTL and tokens per user settings in `LoginView` are now dynamic
Expand Down
1 change: 1 addition & 0 deletions docs/views.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ helper methods:
- `get_context`, to change the context passed to the `UserSerializer`
- `get_token_ttl`, to change the token ttl
- `get_token_limit_per_user`, to change the number of tokens available for a user
- `get_user_serializer_class`, to change the class used for serializing the user

---
When the endpoint authenticates a request, a json object will be returned
Expand Down
11 changes: 7 additions & 4 deletions knox/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ def get_token_ttl(self):
def get_token_limit_per_user(self):
return knox_settings.TOKEN_LIMIT_PER_USER

def get_user_serializer_class(self):
return knox_settings.USER_SERIALIZER

def post(self, request, format=None):
token_limit_per_user = self.get_token_limit_per_user()
if token_limit_per_user is not None:
Expand All @@ -39,11 +42,11 @@ def post(self, request, format=None):
token = AuthToken.objects.create(request.user, token_ttl)
user_logged_in.send(sender=request.user.__class__,
request=request, user=request.user)
UserSerializer = knox_settings.USER_SERIALIZER
UserSerializer = self.get_user_serializer_class()
if UserSerializer is None:
return Response(
{'token': token}
)
return Response({
'token': token
})
context = self.get_context()
return Response({
'user': UserSerializer(request.user, context=context).data,
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# Versions should comply with PEP440. For a discussion on single-sourcing
# the version across setup.py and the project code, see
# https://packaging.python.org/en/latest/single_source_version.html
version='3.5.0',
version='3.6.0',
description='Authentication for django rest framework',
long_description=long_description,
long_description_content_type='text/markdown',
Expand Down

0 comments on commit c1972fc

Please sign in to comment.