mixr-api/api_v1/auth/registration_view.py

26 lines
908 B
Python
Raw Permalink Normal View History

from django.views import View
from django.contrib.auth.models import User
from django.http import HttpResponse
2024-02-29 00:06:45 +01:00
from api_v1.profile.profile_services import acreate_profile
class RegistrationView(View):
async def post(self, request):
# Read parameters from body
username = request.POST.get('username')
password = request.POST.get('password')
email = request.POST.get('email')
display_name = request.POST.get('display_name')
2024-02-29 00:06:45 +01:00
# Check if profile already exists
if User.objects.filter(username=username).exists():
return HttpResponse(status=400, content="User already exists")
2024-02-29 00:06:45 +01:00
# Create profile
user = await User.objects.acreate_user(username, email, password)
# Create UserInformation
2024-02-29 00:06:45 +01:00
await acreate_profile(user, display_name=display_name)
return HttpResponse(status=201, content="User created")