/
views.py
71 lines (44 loc) · 1.92 KB
/
views.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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 JWTAuthMixin, KnoxAuthMixin, SimpleJWTAuthMixin
class HomeSessionView(TemplateView):
template_name = 'home_session.html'
@method_decorator(ensure_csrf_cookie)
def get(self, request, *args, **kwargs):
return super(HomeSessionView, self).get(request, *args, **kwargs)
class HomeTokenView(TemplateView):
template_name = 'home_token.html'
class HomeJWTView(TemplateView):
template_name = 'home_jwt.html'
class HomeJWTOldView(TemplateView):
template_name = 'home_jwt_old.html'
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 UserJWTOldDetailView(JWTAuthMixin, BaseDetailView):
pass
class UserJWTDetailView(SimpleJWTAuthMixin, BaseDetailView):
pass
class UserKnoxDetailView(KnoxAuthMixin, BaseDetailView):
pass