Skip to content

Commit

Permalink
Arreglo generación del audio del captcha (#581)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
marcorichetta authored Sep 25, 2023
1 parent 5f88d1e commit 958cc9b
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 20 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
FROM python:3.9
ENV PYTHONUNBUFFERED 1
ENV PYTHONPATH /code:$PYTHONPATH
RUN apt-get update && apt-get -y install flite=2.2-5
RUN mkdir /code
WORKDIR /code
COPY dev_requirements.txt /code
Expand Down
23 changes: 23 additions & 0 deletions community/templates/account/custom_captcha.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{% load i18n %}
{% spaceless %}
<div class="form-group">
<label class="control-label">{{ label }}</label>
<div class="form-group">
<div class="input-group mb-3">
<div class="input-group-prepend">
<img src="{{ image }}" alt="captcha" class="captcha" />
{% if audio %}
<audio
title="{% trans "Play CAPTCHA as audio file" %}"
src="{{ audio }}"
alt="captcha audio"
controls
style="display: block; padding-bottom: 1rem;"
>
{% endif %}
</div>
{% include "django/forms/widgets/multiwidget.html" %}
</div>
</div>
</div>
{% endspaceless %}
16 changes: 13 additions & 3 deletions pyarweb/forms.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
from allauth.account.forms import SignupForm
from captcha.fields import CaptchaField
from captcha.fields import CaptchaField, CaptchaTextInput


class SingupFormWithCaptcha(SignupForm):
captcha = CaptchaField()
class CustomCaptchaTextInput(CaptchaTextInput):
# HACK - No entiendo por qué esto apunta a community/templates y no al /templates en el root
template_name = "account/custom_captcha.html"

def image_url(self):
# Agrego el "@2" para enviar un captcha con más resolucioón
# https://django-simple-captcha.readthedocs.io/en/latest/advanced.html#captcha-2x-image
return super().image_url().removesuffix("/") + "@2"


class SignupFormWithCaptcha(SignupForm):
captcha = CaptchaField(widget=CustomCaptchaTextInput)
5 changes: 3 additions & 2 deletions pyarweb/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@
#
CAPTCHA_LENGTH = 6
CAPTCHA_FLITE_PATH = "/usr/bin/flite"
CAPTCHA_IMAGE_TEMPLATE = "account/custom_captcha.html"

ALLOWED_HTML_TAGS_INPUT = [
'a',
Expand Down Expand Up @@ -245,7 +244,7 @@

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

ACCOUNT_FORMS = {'signup': 'pyarweb.forms.SingupFormWithCaptcha'}
ACCOUNT_FORMS = {'signup': 'pyarweb.forms.SignupFormWithCaptcha'}

DJANGO_EASY_AUDIT_WATCH_AUTH_EVENTS = False
DJANGO_EASY_AUDIT_WATCH_REQUEST_EVENTS = False
Expand Down Expand Up @@ -290,3 +289,5 @@
'joboffers.publishers.telegram.TelegramPublisher',
'joboffers.publishers.twitter.TwitterPublisher'
]

DEFAULT_AUTO_FIELD = "django.db.models.AutoField"
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ django-extensions==3.1.5
django-html-sanitizer==0.1.5
django-model-utils==4.2.0
django-sendfile==0.3.11
django-simple-captcha==0.5.14
django-simple-captcha==0.5.18
django-storages[azure]==1.11.1
django-summernote==0.8.20.0
django-tagging==0.5.0
Expand Down
14 changes: 0 additions & 14 deletions templates/account/custom_captcha.html

This file was deleted.

0 comments on commit 958cc9b

Please sign in to comment.