Compare commits

...

2 commits

8 changed files with 41 additions and 10 deletions

View file

@ -1,5 +1,5 @@
from django.contrib import admin
from .user.models import *
from .user.models.user_information import UserInformation
# Register your models here.
admin.site.register(UserInformation)

View file

@ -0,0 +1,25 @@
from django.views import View
from django.contrib.auth.models import User
from django.http import HttpResponse
from api_v1.user.user_services import acreate_user_information
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')
# Check if user already exists
if User.objects.filter(username=username).exists():
return HttpResponse(status=400, content="User already exists")
# Create user
user = await User.objects.acreate_user(username, email, password)
# Create UserInformation
await acreate_user_information(user, display_name=display_name)
return HttpResponse(status=201, content="User created")

View file

@ -1 +1 @@
from .user.models import *
from .user.models.user_information import UserInformation

8
api_v1/urls.py Normal file
View file

@ -0,0 +1,8 @@
from django.urls import path, include
from .auth.registration_view import RegistrationView
# Assign register url
urlpatterns = [
path("auth/", include("django.contrib.auth.urls")),
path('auth/register/', RegistrationView.as_view(), name='register'),
]

View file

@ -1,2 +0,0 @@
from .models import *
from .user_services import *

View file

@ -1 +0,0 @@
from .user_information import UserInformation

View file

@ -1,9 +1,9 @@
from .models import UserInformation
from .models.user_information import UserInformation
from django.contrib.auth.models import User
from typing import Optional
async def create_user_information(user: User, *, display_name: Optional[str] = None) -> UserInformation:
async def acreate_user_information(user: User, *, display_name: Optional[str] = None) -> UserInformation:
"""Async. Create a UserInformation object for the given user.
@param user: The user to create the UserInformation object for.
@ -20,7 +20,7 @@ async def create_user_information(user: User, *, display_name: Optional[str] = N
return user_information
async def get_user_information(user: User) -> UserInformation:
async def aget_user_information(user: User) -> UserInformation:
"""Async. Get the UserInformation object for the given user.
@param user: The user to get the UserInformation object for.
@ -29,7 +29,7 @@ async def get_user_information(user: User) -> UserInformation:
return await UserInformation.objects.aget(user)
async def set_user_display_name(user: User, display_name: Optional[str] = None) -> UserInformation:
async def aset_user_display_name(user: User, display_name: Optional[str] = None) -> UserInformation:
"""Async. Set the display name for the given user.
@param user: The user to set the display name for.

View file

@ -15,8 +15,9 @@ Including another URLconf
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path("v1/", include("api_v1.urls")),
]