-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathviews.py
33 lines (27 loc) · 1.12 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
from django.shortcuts import render
from django.http import HttpResponse
from rest_framework import generics, permissions, status, views
from rest_framework.response import Response
from rest_framework_simplejwt.tokens import RefreshToken
from .models import MyUser
from .serializers import UserSerializer, SignupSerializer
def index(request):
return HttpResponse("User Page")
class UserSignupView(generics.CreateAPIView):
queryset = MyUser.objects.all()
serializer_class = SignupSerializer
class UserProfileView(generics.RetrieveAPIView):
permission_classes = [permissions.IsAuthenticated]
serializer_class = UserSerializer
def get_object(self):
return self.request.user
class LogoutView(views.APIView):
permission_classes = [permissions.IsAuthenticated]
def post(self, request):
try:
refresh_token = request.data["refresh"]
token = RefreshToken(refresh_token)
token.blacklist()
return Response(status=status.HTTP_204_NO_CONTENT)
except Exception as e:
return Response({'error': str(e)}, status=status.HTTP_400_BAD_REQUEST)