From 0d473d873d994065d8b2c3a0344c394510bc641b Mon Sep 17 00:00:00 2001 From: JohannesSetiawan Date: Thu, 22 Feb 2024 18:00:00 +0700 Subject: [PATCH] [GREEN] Implemented register feature and pass the test. --- authentication/urls.py | 1 + authentication/views.py | 12 +++++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/authentication/urls.py b/authentication/urls.py index d4b711f..844e389 100644 --- a/authentication/urls.py +++ b/authentication/urls.py @@ -4,4 +4,5 @@ app_name = 'authentication' urlpatterns = [ + path('register/', RegisterView.as_view(), name='register') ] \ No newline at end of file diff --git a/authentication/views.py b/authentication/views.py index 60699e1..7236f05 100644 --- a/authentication/views.py +++ b/authentication/views.py @@ -1,15 +1,17 @@ -from django.shortcuts import render import json from django.http import JsonResponse from authentication.models import * from django.views import View -from django.contrib.auth import authenticate, login, logout from django.utils.decorators import method_decorator from django.views.decorators.csrf import csrf_exempt -import re -from django.core.serializers import serialize @method_decorator(csrf_exempt, name='dispatch') class RegisterView(View): def post(self, request): - return 'None' \ No newline at end of file + data = json.loads(request.body) + username = data['username'] + password = data['password'] + email = data['email'] + new_user = AppUser.objects.create_user(email=email,username=username,password=password) + new_user.save() + return JsonResponse({'msg': 'Success! User registered'}, status=200) \ No newline at end of file