From 1301652ad88736f616c54131f14b46ea4724aca6 Mon Sep 17 00:00:00 2001 From: wbamberg Date: Fri, 16 Aug 2024 21:26:17 -0700 Subject: [PATCH 1/5] Basic registration --- catalog/templates/base_generic.html | 1 + locallibrary/urls.py | 3 ++- locallibrary/views.py | 18 ++++++++++++++++++ templates/registration/register_user.html | 7 +++++++ 4 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 locallibrary/views.py create mode 100644 templates/registration/register_user.html diff --git a/catalog/templates/base_generic.html b/catalog/templates/base_generic.html index df7eab42..d4d57bab 100644 --- a/catalog/templates/base_generic.html +++ b/catalog/templates/base_generic.html @@ -38,6 +38,7 @@ {% else %}
  • Login
  • +
  • Register
  • {% endif %} diff --git a/locallibrary/urls.py b/locallibrary/urls.py index 1dd9547f..94924cbc 100644 --- a/locallibrary/urls.py +++ b/locallibrary/urls.py @@ -45,9 +45,10 @@ path('', RedirectView.as_view(url='/catalog/', permanent=True)), ] - +from .import views # Add Django site authentication urls (for login, logout, password management) urlpatterns += [ path('accounts/', include('django.contrib.auth.urls')), + path('register/', views.register_user, name='register'), ] diff --git a/locallibrary/views.py b/locallibrary/views.py new file mode 100644 index 00000000..b9f37cd8 --- /dev/null +++ b/locallibrary/views.py @@ -0,0 +1,18 @@ + +from django.shortcuts import render, redirect +from django.contrib.auth.forms import UserCreationForm +from django.contrib.auth import login + + +def register_user(request): + if request.method != 'POST': + form = UserCreationForm() + else: + form = UserCreationForm(request.POST) + if form.is_valid(): + user = form.save() + login(request, user) + return redirect('index') + + context = {'form': form} + return render(request, 'registration/register_user.html', context) diff --git a/templates/registration/register_user.html b/templates/registration/register_user.html new file mode 100644 index 00000000..773fd379 --- /dev/null +++ b/templates/registration/register_user.html @@ -0,0 +1,7 @@ +

    Register

    + +
    + {% csrf_token %} {{form.as_p}} + + +
    From 19d6f6bafd18af26dea1af711ddcf791b5b91683 Mon Sep 17 00:00:00 2001 From: wbamberg Date: Sat, 17 Aug 2024 00:13:05 -0700 Subject: [PATCH 2/5] Fix reg link --- catalog/templates/base_generic.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/catalog/templates/base_generic.html b/catalog/templates/base_generic.html index d4d57bab..f1109c9f 100644 --- a/catalog/templates/base_generic.html +++ b/catalog/templates/base_generic.html @@ -38,7 +38,7 @@ {% else %}
  • Login
  • -
  • Register
  • +
  • Register
  • {% endif %} From a397fe9bd540573e8501231e2b39ec04bbfe6e57 Mon Sep 17 00:00:00 2001 From: wbamberg Date: Sat, 17 Aug 2024 00:22:43 -0700 Subject: [PATCH 3/5] Better template --- templates/registration/register_user.html | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/templates/registration/register_user.html b/templates/registration/register_user.html index 773fd379..7cd5ca2b 100644 --- a/templates/registration/register_user.html +++ b/templates/registration/register_user.html @@ -1,7 +1,11 @@ -

    Register

    +{% extends "base_generic.html" %} + +{% block content %}
    {% csrf_token %} {{form.as_p}}
    + +{% endblock %} From 5b6edb243ead2f45e6165a2c61813576c860c7dc Mon Sep 17 00:00:00 2001 From: wbamberg Date: Sat, 17 Aug 2024 08:53:47 -0700 Subject: [PATCH 4/5] Fix import --- locallibrary/urls.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/locallibrary/urls.py b/locallibrary/urls.py index 94924cbc..b5ba2233 100644 --- a/locallibrary/urls.py +++ b/locallibrary/urls.py @@ -35,7 +35,6 @@ from django.conf import settings from django.conf.urls.static import static - urlpatterns+= static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) @@ -45,7 +44,7 @@ path('', RedirectView.as_view(url='/catalog/', permanent=True)), ] -from .import views +from . import views # Add Django site authentication urls (for login, logout, password management) urlpatterns += [ From cbc1275f96368b9ca7524ce3231da82890a66b7c Mon Sep 17 00:00:00 2001 From: Hamish Willee Date: Mon, 19 Aug 2024 12:34:42 +1000 Subject: [PATCH 5/5] Signup password --- locallibrary/forms.py | 11 +++++++++++ locallibrary/views.py | 6 +++--- 2 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 locallibrary/forms.py diff --git a/locallibrary/forms.py b/locallibrary/forms.py new file mode 100644 index 00000000..6817089b --- /dev/null +++ b/locallibrary/forms.py @@ -0,0 +1,11 @@ +from django.contrib.auth.forms import BaseUserCreationForm +from django import forms +from django.contrib.auth.models import User + +class PasswordUserCreationForm(BaseUserCreationForm): + """Form for signing on a new user with an email address""" + email = forms.EmailField(label='email',required=True) + + class Meta: + model = User + fields = ('username', 'email', 'password1', 'password2') \ No newline at end of file diff --git a/locallibrary/views.py b/locallibrary/views.py index b9f37cd8..d235a1be 100644 --- a/locallibrary/views.py +++ b/locallibrary/views.py @@ -1,14 +1,14 @@ from django.shortcuts import render, redirect -from django.contrib.auth.forms import UserCreationForm +from locallibrary.forms import PasswordUserCreationForm from django.contrib.auth import login def register_user(request): if request.method != 'POST': - form = UserCreationForm() + form = PasswordUserCreationForm() else: - form = UserCreationForm(request.POST) + form = PasswordUserCreationForm(request.POST) if form.is_valid(): user = form.save() login(request, user)