import uuid
from rest_framework import viewsets, permissions, status
from rest_framework.response import Response


class UserLogoutAllView(viewsets.ViewSet):
    """
    Use this endpoint to log out all sessions for a given user.
    """

    permission_classes = [permissions.IsAuthenticated]

    def destroy(self, request, *args, **kwargs):
        user = request.user
        user.jwt_secret = uuid.uuid4()
        user.save()
        return Response(status=status.HTTP_204_NO_CONTENT)
