Skip to content

Commit

Permalink
Minor release (#57)
Browse files Browse the repository at this point in the history
* Add missing steps of setup to docs (#48)

* add missing steps of setup to docs

* docs: fix broken numbered list and broken internal link

* Add missing closing brace in docs (#51) (#53)

* Add context to UserSerializer (#56)
  • Loading branch information
belugame authored Apr 24, 2017
1 parent 01112ee commit 7f9d9f0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
19 changes: 17 additions & 2 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ Knox should be installed with pip
pip install django-rest-knox
```

Add `rest_framework` and `knox` to your `INSTALLED_APPS`
## Setup knox

- Add `rest_framework` and `knox` to your `INSTALLED_APPS`, remove
`rest_framework.authtoken` if you were using it.

```python
INSTALLED_APPS = (
Expand All @@ -42,7 +45,19 @@ INSTALLED_APPS = (
)
```

Remember to apply the migrations for the models
- Make knox's TokenAuthentication your default authentification class
for django-rest-framework:

```python
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': ('knox.auth.TokenAuthentication',),
...
}
```

- Add the [knox url patterns](urls.md#urls-knoxurls) to your project.

- Apply the migrations for the models

```bash
python manage.py migrate
Expand Down
10 changes: 5 additions & 5 deletions knox/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
from rest_framework.settings import api_settings
from rest_framework.views import APIView
from rest_framework.generics import GenericAPIView

from knox.auth import TokenAuthentication
from knox.models import AuthToken
from knox.settings import knox_settings


class LoginView(APIView):
class LoginView(GenericAPIView):
authentication_classes = api_settings.DEFAULT_AUTHENTICATION_CLASSES
permission_classes = (IsAuthenticated,)

Expand All @@ -19,12 +19,12 @@ def post(self, request, format=None):
user_logged_in.send(sender=request.user.__class__, request=request, user=request.user)
UserSerializer = knox_settings.USER_SERIALIZER
return Response({
'user': UserSerializer(request.user).data,
'user': UserSerializer(request.user, context=self.get_serializer_context()).data,
'token': token,
})


class LogoutView(APIView):
class LogoutView(GenericAPIView):
authentication_classes = (TokenAuthentication,)
permission_classes = (IsAuthenticated,)

Expand All @@ -34,7 +34,7 @@ def post(self, request, format=None):
return Response(None, status=status.HTTP_204_NO_CONTENT)


class LogoutAllView(APIView):
class LogoutAllView(GenericAPIView):
'''
Log the user out of all sessions
I.E. deletes all auth tokens for the user
Expand Down

0 comments on commit 7f9d9f0

Please sign in to comment.