Registration page linked with backend
This commit is contained in:
parent
e78586bbd6
commit
8349d9ff26
@ -4,19 +4,18 @@
|
||||
|
||||
{% block content %}
|
||||
<h2>Register</h2>
|
||||
<form action="">
|
||||
<p>First Name</p>
|
||||
<input type="text" placeholder="Enter First Name">
|
||||
<p>Last Name</p>
|
||||
<input type="text" placeholder="Enter Last Name">
|
||||
<p>Email</p>
|
||||
<input type="email" placeholder="Enter Email">
|
||||
<p>Password</p>
|
||||
<input type="password" placeholder="Enter Password">
|
||||
<p>Repeat password</p>
|
||||
<input type="password" placeholder="Enter Password">
|
||||
<form method="post"> {% csrf_token %}
|
||||
|
||||
{% for field in registration_form %}
|
||||
<p>
|
||||
{{field.label_tag}}
|
||||
{{field}}
|
||||
{% for error in field.errors %}
|
||||
<p style="color: red;">{{error}}</p>
|
||||
{% endfor %}
|
||||
</p>
|
||||
{% endfor %}
|
||||
<input type="submit" value="Crete account">
|
||||
<p><input type="checkbox">Remember Me</p>
|
||||
</form>
|
||||
{% endblock %}
|
||||
|
||||
|
9
templates/registerSuccess.html
Normal file
9
templates/registerSuccess.html
Normal file
@ -0,0 +1,9 @@
|
||||
{% extends "authBase.html" %}
|
||||
|
||||
{% block title %}Log Out{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<p>Account have been created successfully. Now you can log in</p>
|
||||
<a href="{% url 'login' %}">Log in now</a>
|
||||
{% endblock %}
|
||||
|
14
users/forms.py
Normal file
14
users/forms.py
Normal file
@ -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")
|
@ -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()),
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user