2024-02-28 17:33:16 +01:00
|
|
|
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
|
2024-02-28 17:33:16 +01:00
|
|
|
|
|
|
|
|
|
|
|
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
|
2024-02-28 17:33:16 +01:00
|
|
|
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
|
2024-02-28 17:33:16 +01:00
|
|
|
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)
|
2024-02-28 17:33:16 +01:00
|
|
|
|
|
|
|
return HttpResponse(status=201, content="User created")
|