mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-27 12:04:02 +03:00
20 lines
626 B
Python
20 lines
626 B
Python
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")
|
|
|