diff options
| author | Rob Romano | 2012-11-10 16:17:50 -0800 |
|---|---|---|
| committer | Rob Romano | 2012-11-10 16:17:50 -0800 |
| commit | 063c027c7b4278620fda6cf4aa7825a817748cc0 (patch) | |
| tree | 2e38d0bb97e1f26b958dc41b923bfb1a466eed73 /rest_framework/authtoken/views.py | |
| parent | e029e44477111ed16da8954a53dcf08c08cfb403 (diff) | |
| download | django-rest-framework-063c027c7b4278620fda6cf4aa7825a817748cc0.tar.bz2 | |
Added authtoken login/logout urlpatterns and views
Diffstat (limited to 'rest_framework/authtoken/views.py')
| -rw-r--r-- | rest_framework/authtoken/views.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/rest_framework/authtoken/views.py b/rest_framework/authtoken/views.py index e69de29b..a52f0a77 100644 --- a/rest_framework/authtoken/views.py +++ b/rest_framework/authtoken/views.py @@ -0,0 +1,19 @@ +from rest_framework.views import APIView +from rest_framework.generics import CreateAPIView +from rest_framework.authtoken.models import Token +from rest_framework.authtoken.serializers import AuthTokenSerializer +from django.http import HttpResponse + +class AuthTokenLoginView(CreateAPIView): + model = Token + serializer_class = AuthTokenSerializer + + +class AuthTokenLogoutView(APIView): + def post(self, request): + if request.user.is_authenticated() and request.auth: + request.auth.delete() + return HttpResponse("logged out") + else: + return HttpResponse("not logged in") + |
