# Path: rest_social_auth/serializers.py
# class UserSerializer(serializers.ModelSerializer):
# 
#     class Meta:
#         model = get_user_model()
#         # Custom user model may not have some fields from the list below,
#         # excluding them based on actual fields
#         exclude = [
#             field for field in (
#                 'is_staff', 'is_active', 'date_joined', 'password', 'last_login',
#                 'user_permissions', 'groups', 'is_superuser',
#             ) if field in [mfield.name for mfield in get_user_model()._meta.get_fields()]
#         ]
# 
# Path: rest_social_auth/views.py
# class KnoxAuthMixin(object):
#     def get_authenticators(self):
#         try:
#             from knox.auth import TokenAuthentication
#         except ImportError:
#             warnings.warn(
#                 'django-rest-knox must be installed for Knox authentication',
#                 ImportWarning,
#             )
#             raise
# 
#         return [TokenAuthentication()]
# 
# class SimpleJWTAuthMixin(object):
#     def get_authenticators(self):
#         try:
#             from rest_framework_simplejwt.authentication import JWTAuthentication
#         except ImportError:
#             warnings.warn(
#                 'django-rest-framework-simplejwt must be installed for JWT authentication',
#                 ImportWarning,
#             )
#             raise
# 
#         return [JWTAuthentication()]


from django.views.generic import TemplateView
from django.contrib.auth import logout, get_user_model
from django.utils.decorators import method_decorator
from django.views.decorators.csrf import ensure_csrf_cookie
from rest_framework import generics, status
from rest_framework.permissions import IsAuthenticated
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework.authentication import SessionAuthentication, TokenAuthentication
from rest_social_auth.serializers import UserSerializer
from rest_social_auth.views import KnoxAuthMixin, SimpleJWTAuthMixin


class HomeKnoxView(TemplateView):
    template_name = 'home_knox.html'


class LogoutSessionView(APIView):

    def post(self, request, *args, **kwargs):
        logout(request)
        return Response(status=status.HTTP_204_NO_CONTENT)


class BaseDetailView(generics.RetrieveAPIView):
    permission_classes = IsAuthenticated,
    serializer_class = UserSerializer
    model = get_user_model()

    def get_object(self, queryset=None):
        return self.request.user


class UserSessionDetailView(BaseDetailView):
    authentication_classes = (SessionAuthentication, )


class UserTokenDetailView(BaseDetailView):
    authentication_classes = (TokenAuthentication, )



# Path: rest_social_auth/serializers.py
# class UserSerializer(serializers.ModelSerializer):
# 
#     class Meta:
#         model = get_user_model()
#         # Custom user model may not have some fields from the list below,
#         # excluding them based on actual fields
#         exclude = [
#             field for field in (
#                 'is_staff', 'is_active', 'date_joined', 'password', 'last_login',
#                 'user_permissions', 'groups', 'is_superuser',
#             ) if field in [mfield.name for mfield in get_user_model()._meta.get_fields()]
#         ]
# 
# Path: rest_social_auth/views.py
# class KnoxAuthMixin(object):
#     def get_authenticators(self):
#         try:
#             from knox.auth import TokenAuthentication
#         except ImportError:
#             warnings.warn(
#                 'django-rest-knox must be installed for Knox authentication',
#                 ImportWarning,
#             )
#             raise
# 
#         return [TokenAuthentication()]
# 
# class SimpleJWTAuthMixin(object):
#     def get_authenticators(self):
#         try:
#             from rest_framework_simplejwt.authentication import JWTAuthentication
#         except ImportError:
#             warnings.warn(
#                 'django-rest-framework-simplejwt must be installed for JWT authentication',
#                 ImportWarning,
#             )
#             raise
# 
#         return [JWTAuthentication()]


# Path: example_project/users/views.py
from django.views.generic import TemplateView
from django.contrib.auth import logout, get_user_model
from django.utils.decorators import method_decorator
from django.views.decorators.csrf import ensure_csrf_cookie
from rest_framework import generics, status
from rest_framework.permissions import IsAuthenticated
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework.authentication import SessionAuthentication, TokenAuthentication
from rest_social_auth.serializers import UserSerializer
from rest_social_auth.views import KnoxAuthMixin, SimpleJWTAuthMixin



class HomeKnoxView(TemplateView):
    template_name = 'home_knox.html'


class LogoutSessionView(APIView):

    def post(self, request, *args, **kwargs):
        logout(request)
        return Response(status=status.HTTP_204_NO_CONTENT)


class BaseDetailView(generics.RetrieveAPIView):
    permission_classes = IsAuthenticated,
    serializer_class = UserSerializer
    model = get_user_model()

    def get_object(self, queryset=None):
        return self.request.user


class UserSessionDetailView(BaseDetailView):
    authentication_classes = (SessionAuthentication, )


class UserTokenDetailView(BaseDetailView):
    authentication_classes = (TokenAuthentication, )



class UserJWTDetailView(SimpleJWTAuthMixin, BaseDetailView):