You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
flyapps/fir_ser/api/views/logout.py

22 lines
707 B

from rest_framework.views import APIView
from api.utils.auth import ExpiringTokenAuthentication
from api.models import Token
from django.core.cache import cache
from rest_framework.response import Response
from django.contrib import auth
import logging
logger = logging.getLogger(__file__)
class LogoutView(APIView):
authentication_classes = [ExpiringTokenAuthentication]
def delete(self, request):
logger.info("user:%s logout" % (request.user))
user = request.user.pk
auth_token = request.auth
cache.delete(auth_token)
Token.objects.filter(user=user, access_token=auth_token).delete()
auth.logout(request)
return Response({"code": 1000})