diff --git a/templates/register.html b/templates/register.html index a5a39b6..1799eb8 100644 --- a/templates/register.html +++ b/templates/register.html @@ -4,19 +4,18 @@ {% block content %}
Account have been created successfully. Now you can log in
+ Log in now +{% endblock %} + diff --git a/users/forms.py b/users/forms.py new file mode 100644 index 0000000..fdefaaa --- /dev/null +++ b/users/forms.py @@ -0,0 +1,14 @@ +from django import forms +from django.contrib.auth.forms import UserCreationForm +from .models import User + +class RegistrationForm(UserCreationForm): + email = forms.EmailField(max_length=60, widget=forms.EmailInput(attrs={'placeholder': 'Enter Email'})) + first_name = forms.CharField(max_length=60, widget=forms.TextInput(attrs={'placeholder': 'Enter First Name'})) + last_name = forms.CharField(max_length=60, widget=forms.TextInput(attrs={'placeholder': 'Enter Last Name'})) + password1 = forms.CharField(widget=forms.PasswordInput(attrs={'placeholder': 'Enter Password'})) + password2 = forms.CharField(widget=forms.PasswordInput(attrs={'placeholder': 'Repeat Password'})) + + class Meta: + model = User + fields = ("email", "first_name", "last_name", "password1", "password2") \ No newline at end of file diff --git a/users/urls.py b/users/urls.py index f0097f2..1c75f05 100644 --- a/users/urls.py +++ b/users/urls.py @@ -4,7 +4,7 @@ from django.urls import path from users.views import UserModelViewSet from rest_framework_simplejwt.views import TokenObtainPairView from rest_framework_simplejwt.views import TokenRefreshView -from .views import PasswordReset, UserPasswordResetConfirmView, RegisterViewSet, login, logout, register +from .views import PasswordReset, UserPasswordResetConfirmView, RegisterViewSet, login, logout, register, register_success router = DefaultRouter(trailing_slash=False) @@ -13,9 +13,11 @@ router.register("items", UserModelViewSet) urlpatterns = [ path("", include(router.urls)), - path('login', login, name='register'), - path('logout', logout, name='register'), - path('register', RegisterViewSet.as_view(), name='register'), + path('login', login, name='login'), + path('logout', logout, name='logout'), + path('register/success', register_success, name='register_success'), + # path('register', RegisterViewSet.as_view(), name='register'), + path('register', register, name='register'), path('api/token', TokenObtainPairView.as_view(), name='token_obtain_pair'), path('api/token/refresh', TokenRefreshView.as_view(), name='token_refresh'), path("password/reset", PasswordReset.as_view()), diff --git a/users/views.py b/users/views.py index 573af3f..b62d505 100644 --- a/users/views.py +++ b/users/views.py @@ -9,6 +9,7 @@ from .serializers import UserPasswordResetSerializer, UserPasswordResetConfirmSe from rest_framework.response import Response from django.shortcuts import render, redirect from django.template import loader +from .forms import RegistrationForm @@ -77,8 +78,24 @@ def logout(request): # } return render(request, 'logout.html') +def register_success(request): + return render(request, 'registerSuccess.html') + def register(request): - # context = { - # 'latest_question_list': latest_question_list, - # } - return render(request, 'register.html') + context = {} + if request.POST: + form = RegistrationForm(request.POST) + if form.is_valid(): + User.objects.create( + email=form.cleaned_data["email"], + first_name=form.cleaned_data["first_name"], + last_name=form.cleaned_data["last_name"], + password=form.cleaned_data["password1"] + ) + return redirect('register_success') + else: + context['registration_form'] = form + else: + form = RegistrationForm() + context['registration_form'] = form + return render(request, 'register.html', context)