Working on registration endpoint and authentication in general
This commit is contained in:
parent
398a2c7c08
commit
a103ac22f5
8 changed files with 38 additions and 7 deletions
|
@ -1,5 +1,5 @@
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from .user.models import *
|
from .user.models.user_information import UserInformation
|
||||||
|
|
||||||
# Register your models here.
|
# Register your models here.
|
||||||
admin.site.register(UserInformation)
|
admin.site.register(UserInformation)
|
||||||
|
|
25
api_v1/auth/registration_view.py
Normal file
25
api_v1/auth/registration_view.py
Normal 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")
|
|
@ -1 +1 @@
|
||||||
from .user.models import *
|
from .user.models.user_information import UserInformation
|
||||||
|
|
8
api_v1/urls.py
Normal file
8
api_v1/urls.py
Normal 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'),
|
||||||
|
]
|
|
@ -1,2 +0,0 @@
|
||||||
from .models import *
|
|
||||||
from .user_services import *
|
|
|
@ -1 +0,0 @@
|
||||||
from .user_information import UserInformation
|
|
|
@ -1,4 +1,4 @@
|
||||||
from .models import UserInformation
|
from .models.user_information import UserInformation
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
|
|
|
@ -15,8 +15,9 @@ Including another URLconf
|
||||||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||||
"""
|
"""
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.urls import path
|
from django.urls import path, include
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('admin/', admin.site.urls),
|
path('admin/', admin.site.urls),
|
||||||
|
path("v1/", include("api_v1.urls")),
|
||||||
]
|
]
|
||||||
|
|
Loading…
Reference in a new issue