Add captcha to signup page

This commit is contained in:
Nathan Chapman 2023-05-07 19:38:44 -06:00
parent 319c50cf4f
commit 730721d204
7 changed files with 44 additions and 4 deletions

View File

@ -1,6 +1,6 @@
FROM python:3.11-alpine3.17 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 \ ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \ PYTHONUNBUFFERED=1 \

View File

@ -1,6 +1,7 @@
from django import forms from django import forms
from django.contrib.auth.forms import UserCreationForm, UserChangeForm from django.contrib.auth.forms import UserCreationForm, UserChangeForm
from allauth.account.forms import SignupForm from allauth.account.forms import SignupForm
from captcha.fields import CaptchaField
from .models import Address, User from .models import Address, User
@ -60,3 +61,4 @@ class UserSignupForm(SignupForm):
required=True, required=True,
widget=forms.TextInput(attrs={'placeholder': 'Last name'}) widget=forms.TextInput(attrs={'placeholder': 'Last name'})
) )
captcha = CaptchaField()

36
poetry.lock generated
View File

@ -388,6 +388,17 @@ django = ">=2.2"
django-appconf = ">=1.0.2" django-appconf = ">=1.0.2"
measurement = ">=1.6,<4.0" 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]] [[package]]
name = "django-render-block" name = "django-render-block"
version = "0.9.2" version = "0.9.2"
@ -402,6 +413,22 @@ django = ">=2.2"
[package.extras] [package.extras]
dev = ["Jinja2 (>=2.8)"] 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]] [[package]]
name = "django-storages" name = "django-storages"
version = "1.13.2" version = "1.13.2"
@ -1105,7 +1132,7 @@ python-versions = ">=3.4"
[metadata] [metadata]
lock-version = "1.1" lock-version = "1.1"
python-versions = "^3.11" python-versions = "^3.11"
content-hash = "663ce94cf571267e695ad5ac8304d7a44603d0c081528fc72e88fb87196cf928" content-hash = "6624d86a540ead66402daae3c3353c3a26f2f8bc9293676b68e1c2e8199e385a"
[metadata.files] [metadata.files]
amqp = [ amqp = [
@ -1396,10 +1423,17 @@ django-measurement = [
{file = "django-measurement-3.2.4.tar.gz", hash = "sha256:db1279b04bacf3b48259312adaaefcfe55ca30b1e0933fa37d6c387c156834d5"}, {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"}, {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 = [ django-render-block = [
{file = "django-render-block-0.9.2.tar.gz", hash = "sha256:3dde0d2abde9381685659d2ed0761b8bddf7741c48eaadec9e5b50a6c7850247"}, {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"}, {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 = [ django-storages = [
{file = "django-storages-1.13.2.tar.gz", hash = "sha256:cbadd15c909ceb7247d4ffc503f12a9bec36999df8d0bef7c31e57177d512688"}, {file = "django-storages-1.13.2.tar.gz", hash = "sha256:cbadd15c909ceb7247d4ffc503f12a9bec36999df8d0bef7c31e57177d512688"},
{file = "django_storages-1.13.2-py3-none-any.whl", hash = "sha256:31dc5a992520be571908c4c40d55d292660ece3a55b8141462b4e719aa38eab3"}, {file = "django_storages-1.13.2-py3-none-any.whl", hash = "sha256:31dc5a992520be571908c4c40d55d292660ece3a55b8141462b4e719aa38eab3"},

View File

@ -82,6 +82,7 @@ INSTALLED_APPS = [
'allauth.account', 'allauth.account',
'allauth.socialaccount', 'allauth.socialaccount',
'analytical', 'analytical',
'captcha',
# Local # Local
'accounts.apps.AccountsConfig', 'accounts.apps.AccountsConfig',

View File

@ -9,9 +9,8 @@ urlpatterns = [
path('accounts/', include('allauth.urls')), path('accounts/', include('allauth.urls')),
path('accounts/', include(('accounts.urls', 'accounts'), namespace='accounts')), path('accounts/', include(('accounts.urls', 'accounts'), namespace='accounts')),
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
path('captcha/', include('captcha.urls')),
] ]
if settings.DEBUG: if settings.DEBUG:
urlpatterns += [path('__debug__/', include('debug_toolbar.urls'))] 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)

View File

@ -34,6 +34,7 @@ pycodestyle = "^2.10.0"
environs = "^9.5.0" environs = "^9.5.0"
python-dotenv = "^0.21.0" python-dotenv = "^0.21.0"
py-moneyed = "^3.0" py-moneyed = "^3.0"
django-simple-captcha = "^0.5.17"
[build-system] [build-system]

View File

@ -163,6 +163,9 @@ class Cart:
elif item.quantity > item.variant.product.checkout_limit: elif item.quantity > item.variant.product.checkout_limit:
messages.warning(self.request, 'Quantity exceeds checkout limit.') messages.warning(self.request, 'Quantity exceeds checkout limit.')
item.quantity = item.variant.product.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): def check_max_cart_quantity(self):
if len(self) > self.site_settings.max_cart_quantity: if len(self) > self.site_settings.max_cart_quantity: