TurTaskWeb/backend/users/views.py
2023-11-04 03:51:20 +07:00

28 lines
859 B
Python

"""This module defines API views for user creation"""
from rest_framework import status
from rest_framework.permissions import AllowAny
from rest_framework.response import Response
from rest_framework.views import APIView
from .serializers import CustomUserSerializer
class CustomUserCreate(APIView):
"""
Custom User Creation View.
Allows users to create new accounts.
"""
permission_classes = (AllowAny,)
def post(self, request):
"""
Create a new user account based on the provided data.
"""
serializer = CustomUserSerializer(data=request.data)
if serializer.is_valid():
user = serializer.save()
if user:
return Response(serializer.data, status=status.HTTP_201_CREATED)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)