Skip to content

Commit 958cc9b

Browse files
authoredSep 25, 2023
Arreglo generación del audio del captcha (#581)
* fix DEFAULT_AUTO_FIELD warnings * upgrade django-simple-captcha and add flite * fix: flake & typo * define captcha form with new rendering style https://django-simple-captcha.readthedocs.io/en/latest/advanced.html#rendering * serve a double resolution captcha
1 parent 5f88d1e commit 958cc9b

File tree

6 files changed

+41
-20
lines changed

6 files changed

+41
-20
lines changed
 

‎Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
FROM python:3.9
22
ENV PYTHONUNBUFFERED 1
33
ENV PYTHONPATH /code:$PYTHONPATH
4+
RUN apt-get update && apt-get -y install flite=2.2-5
45
RUN mkdir /code
56
WORKDIR /code
67
COPY dev_requirements.txt /code
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{% load i18n %}
2+
{% spaceless %}
3+
<div class="form-group">
4+
<label class="control-label">{{ label }}</label>
5+
<div class="form-group">
6+
<div class="input-group mb-3">
7+
<div class="input-group-prepend">
8+
<img src="{{ image }}" alt="captcha" class="captcha" />
9+
{% if audio %}
10+
<audio
11+
title="{% trans "Play CAPTCHA as audio file" %}"
12+
src="{{ audio }}"
13+
alt="captcha audio"
14+
controls
15+
style="display: block; padding-bottom: 1rem;"
16+
>
17+
{% endif %}
18+
</div>
19+
{% include "django/forms/widgets/multiwidget.html" %}
20+
</div>
21+
</div>
22+
</div>
23+
{% endspaceless %}

‎pyarweb/forms.py

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
from allauth.account.forms import SignupForm
2-
from captcha.fields import CaptchaField
2+
from captcha.fields import CaptchaField, CaptchaTextInput
33

44

5-
class SingupFormWithCaptcha(SignupForm):
6-
captcha = CaptchaField()
5+
class CustomCaptchaTextInput(CaptchaTextInput):
6+
# HACK - No entiendo por qué esto apunta a community/templates y no al /templates en el root
7+
template_name = "account/custom_captcha.html"
8+
9+
def image_url(self):
10+
# Agrego el "@2" para enviar un captcha con más resolucioón
11+
# https://django-simple-captcha.readthedocs.io/en/latest/advanced.html#captcha-2x-image
12+
return super().image_url().removesuffix("/") + "@2"
13+
14+
15+
class SignupFormWithCaptcha(SignupForm):
16+
captcha = CaptchaField(widget=CustomCaptchaTextInput)

‎pyarweb/settings/base.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,6 @@
191191
#
192192
CAPTCHA_LENGTH = 6
193193
CAPTCHA_FLITE_PATH = "/usr/bin/flite"
194-
CAPTCHA_IMAGE_TEMPLATE = "account/custom_captcha.html"
195194

196195
ALLOWED_HTML_TAGS_INPUT = [
197196
'a',
@@ -245,7 +244,7 @@
245244

246245
GOOGLE_TRACKING_ID = os.environ.get('GOOGLE_TRACKING_ID', '')
247246

248-
ACCOUNT_FORMS = {'signup': 'pyarweb.forms.SingupFormWithCaptcha'}
247+
ACCOUNT_FORMS = {'signup': 'pyarweb.forms.SignupFormWithCaptcha'}
249248

250249
DJANGO_EASY_AUDIT_WATCH_AUTH_EVENTS = False
251250
DJANGO_EASY_AUDIT_WATCH_REQUEST_EVENTS = False
@@ -290,3 +289,5 @@
290289
'joboffers.publishers.telegram.TelegramPublisher',
291290
'joboffers.publishers.twitter.TwitterPublisher'
292291
]
292+
293+
DEFAULT_AUTO_FIELD = "django.db.models.AutoField"

‎requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ django-extensions==3.1.5
1212
django-html-sanitizer==0.1.5
1313
django-model-utils==4.2.0
1414
django-sendfile==0.3.11
15-
django-simple-captcha==0.5.14
15+
django-simple-captcha==0.5.18
1616
django-storages[azure]==1.11.1
1717
django-summernote==0.8.20.0
1818
django-tagging==0.5.0

‎templates/account/custom_captcha.html

-14
This file was deleted.

0 commit comments

Comments
 (0)