Created
August 27, 2020 00:58
-
-
Save BrockHerion/192b002c871baaa26a678f5bfada11fe to your computer and use it in GitHub Desktop.
Registration, Login, and All Users Views
This file contains hidden or 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 rest_framework import status | |
from rest_framework.views import APIView | |
from rest_framework.response import Response | |
from rest_framework.permissions import AllowAny, IsAuthenticated | |
from .serializers import ( | |
UserRegistrationSerializer, | |
UserLoginSerializer, | |
UserListSerializer | |
) | |
from .models import User | |
class AuthUserRegistrationView(APIView): | |
serializer_class = UserRegistrationSerializer | |
permission_classes = (AllowAny, ) | |
def post(self, request): | |
serializer = self.serializer_class(data=request.data) | |
valid = serializer.is_valid(raise_exception=True) | |
if valid: | |
serializer.save() | |
status_code = status.HTTP_201_CREATED | |
response = { | |
'success': True, | |
'statusCode': status_code, | |
'message': 'User successfully registered!', | |
'user': serializer.data | |
} | |
return Response(response, status=status_code) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment