diff options
| author | Rob Romano | 2012-11-10 16:17:50 -0800 |
|---|---|---|
| committer | Rob Romano | 2012-11-14 12:46:14 -0800 |
| commit | bd92db3c672137fa68185dbc0f453f7cea7caff3 (patch) | |
| tree | 6e585d094b68b51e0a2dee9c83a536536f275d94 /rest_framework/authtoken | |
| parent | 4a2526bd1e067104a1553a3e158016fe9ad285bb (diff) | |
| download | django-rest-framework-bd92db3c672137fa68185dbc0f453f7cea7caff3.tar.bz2 | |
Added authtoken login/logout urlpatterns and views
Diffstat (limited to 'rest_framework/authtoken')
| -rw-r--r-- | rest_framework/authtoken/urls.py | 6 | ||||
| -rw-r--r-- | rest_framework/authtoken/views.py | 19 |
2 files changed, 22 insertions, 3 deletions
diff --git a/rest_framework/authtoken/urls.py b/rest_framework/authtoken/urls.py index 2a3e8115..8bea46c0 100644 --- a/rest_framework/authtoken/urls.py +++ b/rest_framework/authtoken/urls.py @@ -13,9 +13,9 @@ your authentication settings include `TokenAuthentication`. ) """ from django.conf.urls.defaults import patterns, url -from rest_framework.authtoken.views import AuthTokenView +from rest_framework.authtoken.views import AuthTokenLoginView, AuthTokenLogoutView urlpatterns = patterns('rest_framework.authtoken.views', - url(r'^login/$', AuthTokenView.as_view(), name='token_login'), -# url(r'^logout/$', 'token_logout', name='token_logout'), + url(r'^login/$', AuthTokenLoginView.as_view(), name='token_login'), + url(r'^logout/$', AuthTokenLogoutView.as_view(), name='token_logout'), ) 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") + |
