Created
March 9, 2021 16:18
-
-
Save therealak12/5704dbbedbf2f8ee54b5b6333d58b095 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.contrib.auth import get_user_model | |
from rest_framework.response import Response | |
from rest_framework.status import HTTP_201_CREATED, HTTP_400_BAD_REQUEST | |
from rest_framework.views import APIView | |
from rest_framework_simplejwt.views import TokenObtainPairView | |
from ..serializers.user import UserSerializer, TokenObtainPairSerializer | |
class RegisterView(APIView): | |
http_method_names = ['post'] | |
def post(self, *args, **kwargs): | |
serializer = UserSerializer(data=self.request.data) | |
if serializer.is_valid(): | |
get_user_model().objects.create_user(**serializer.validated_data) | |
return Response(status=HTTP_201_CREATED) | |
return Response(status=HTTP_400_BAD_REQUEST, data={'errors': serializer.errors}) | |
class EmailTokenObtainPairView(TokenObtainPairView): | |
serializer_class = TokenObtainPairSerializer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment