From 730721d204fa1ca11c75f8348e942f73c333ec2b Mon Sep 17 00:00:00 2001 From: Nathan Chapman Date: Sun, 7 May 2023 19:38:44 -0600 Subject: [PATCH] Add captcha to signup page --- Dockerfile | 2 +- accounts/forms.py | 2 ++ poetry.lock | 36 +++++++++++++++++++++++++++++++++++- ptcoffee/settings.py | 1 + ptcoffee/urls.py | 3 +-- pyproject.toml | 1 + storefront/cart.py | 3 +++ 7 files changed, 44 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index c24d7c0..83ef2f2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ FROM python:3.11-alpine3.17 -RUN apk add build-base libpq-dev +RUN apk add build-base libpq-dev jpeg-dev zlib-dev freetype-dev ENV PYTHONDONTWRITEBYTECODE=1 \ PYTHONUNBUFFERED=1 \ diff --git a/accounts/forms.py b/accounts/forms.py index d4747f0..84852f6 100644 --- a/accounts/forms.py +++ b/accounts/forms.py @@ -1,6 +1,7 @@ from django import forms from django.contrib.auth.forms import UserCreationForm, UserChangeForm from allauth.account.forms import SignupForm +from captcha.fields import CaptchaField from .models import Address, User @@ -60,3 +61,4 @@ class UserSignupForm(SignupForm): required=True, widget=forms.TextInput(attrs={'placeholder': 'Last name'}) ) + captcha = CaptchaField() diff --git a/poetry.lock b/poetry.lock index 97c5b38..4ab2721 100644 --- a/poetry.lock +++ b/poetry.lock @@ -388,6 +388,17 @@ django = ">=2.2" django-appconf = ">=1.0.2" measurement = ">=1.6,<4.0" +[[package]] +name = "django-ranged-response" +version = "0.2.0" +description = "Modified Django FileResponse that adds Content-Range headers." +category = "main" +optional = false +python-versions = "*" + +[package.dependencies] +django = "*" + [[package]] name = "django-render-block" version = "0.9.2" @@ -402,6 +413,22 @@ django = ">=2.2" [package.extras] dev = ["Jinja2 (>=2.8)"] +[[package]] +name = "django-simple-captcha" +version = "0.5.17" +description = "A very simple, yet powerful, Django captcha application" +category = "main" +optional = false +python-versions = "*" + +[package.dependencies] +Django = ">=2.2" +django-ranged-response = "0.2.0" +Pillow = ">=6.2.0" + +[package.extras] +test = ["testfixtures"] + [[package]] name = "django-storages" version = "1.13.2" @@ -1105,7 +1132,7 @@ python-versions = ">=3.4" [metadata] lock-version = "1.1" python-versions = "^3.11" -content-hash = "663ce94cf571267e695ad5ac8304d7a44603d0c081528fc72e88fb87196cf928" +content-hash = "6624d86a540ead66402daae3c3353c3a26f2f8bc9293676b68e1c2e8199e385a" [metadata.files] amqp = [ @@ -1396,10 +1423,17 @@ django-measurement = [ {file = "django-measurement-3.2.4.tar.gz", hash = "sha256:db1279b04bacf3b48259312adaaefcfe55ca30b1e0933fa37d6c387c156834d5"}, {file = "django_measurement-3.2.4-py2.py3-none-any.whl", hash = "sha256:b2d40b8b56b4e8277130a2a8cbc1f01f597589a636e0ea7dfbc4e4c05d458cef"}, ] +django-ranged-response = [ + {file = "django-ranged-response-0.2.0.tar.gz", hash = "sha256:f71fff352a37316b9bead717fc76e4ddd6c9b99c4680cdf4783b9755af1cf985"}, +] django-render-block = [ {file = "django-render-block-0.9.2.tar.gz", hash = "sha256:3dde0d2abde9381685659d2ed0761b8bddf7741c48eaadec9e5b50a6c7850247"}, {file = "django_render_block-0.9.2-py3-none-any.whl", hash = "sha256:1768832be78476c36627b3e3a8e7d9eb0e2bc46b84daf2c51958e2f674173c40"}, ] +django-simple-captcha = [ + {file = "django-simple-captcha-0.5.17.tar.gz", hash = "sha256:9649e66dab4e71efacbfef02f48b83b91684898352a1ab56f1686ce71033b328"}, + {file = "django_simple_captcha-0.5.17-py2.py3-none-any.whl", hash = "sha256:f9a07e5e9de264ba4039c9eaad66bc48188a21ceda5fcdc2fa13c5512141c2c9"}, +] django-storages = [ {file = "django-storages-1.13.2.tar.gz", hash = "sha256:cbadd15c909ceb7247d4ffc503f12a9bec36999df8d0bef7c31e57177d512688"}, {file = "django_storages-1.13.2-py3-none-any.whl", hash = "sha256:31dc5a992520be571908c4c40d55d292660ece3a55b8141462b4e719aa38eab3"}, diff --git a/ptcoffee/settings.py b/ptcoffee/settings.py index 784ca5d..b2ff1e6 100644 --- a/ptcoffee/settings.py +++ b/ptcoffee/settings.py @@ -82,6 +82,7 @@ INSTALLED_APPS = [ 'allauth.account', 'allauth.socialaccount', 'analytical', + 'captcha', # Local 'accounts.apps.AccountsConfig', diff --git a/ptcoffee/urls.py b/ptcoffee/urls.py index ccc1c41..6c5d88c 100644 --- a/ptcoffee/urls.py +++ b/ptcoffee/urls.py @@ -9,9 +9,8 @@ urlpatterns = [ path('accounts/', include('allauth.urls')), path('accounts/', include(('accounts.urls', 'accounts'), namespace='accounts')), path('admin/', admin.site.urls), + path('captcha/', include('captcha.urls')), ] if settings.DEBUG: urlpatterns += [path('__debug__/', include('debug_toolbar.urls'))] - # urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) - # urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) diff --git a/pyproject.toml b/pyproject.toml index a582dae..6293432 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -34,6 +34,7 @@ pycodestyle = "^2.10.0" environs = "^9.5.0" python-dotenv = "^0.21.0" py-moneyed = "^3.0" +django-simple-captcha = "^0.5.17" [build-system] diff --git a/storefront/cart.py b/storefront/cart.py index 8616b8c..16f96f8 100644 --- a/storefront/cart.py +++ b/storefront/cart.py @@ -163,6 +163,9 @@ class Cart: elif item.quantity > item.variant.product.checkout_limit: messages.warning(self.request, 'Quantity exceeds checkout limit.') item.quantity = item.variant.product.checkout_limit + elif item.quantity > item.variant.product.checkout_limit: + messages.warning(self.request, 'Quantity exceeds checkout limit.') + item.quantity = item.variant.product.checkout_limit def check_max_cart_quantity(self): if len(self) > self.site_settings.max_cart_quantity: