From 47dd078b6ae6e5c7a9ab5c28cbbabfae96ec0503 Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Thu, 4 Mar 2021 17:56:42 +0100 Subject: [PATCH] Remplace recaptcha par hcaptcha --- gestioasso/settings/cof_prod.py | 2 +- petitscours/forms.py | 18 ++++++++++++++++-- requirements.txt | 2 +- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/gestioasso/settings/cof_prod.py b/gestioasso/settings/cof_prod.py index 3104e5b0..1865e7e3 100644 --- a/gestioasso/settings/cof_prod.py +++ b/gestioasso/settings/cof_prod.py @@ -50,7 +50,7 @@ INSTALLED_APPS = ( + [ "bda", "petitscours", - "captcha", + "hcaptcha", "kfet", "kfet.open", "channels", diff --git a/petitscours/forms.py b/petitscours/forms.py index 01d4178a..0d9f38bc 100644 --- a/petitscours/forms.py +++ b/petitscours/forms.py @@ -1,14 +1,28 @@ -from captcha.fields import ReCaptchaField from django import forms from django.contrib.auth.models import User from django.forms import ModelForm from django.forms.models import inlineformset_factory +from django.utils.translation import gettext_lazy as _ +from hcaptcha.fields import hCaptchaField from petitscours.models import PetitCoursAbility, PetitCoursDemande +class hCaptchaFieldWithErrors(hCaptchaField): + """ + Pour l'instant, hCaptchaField ne supporte pas le paramètre `error_messages` lors de + l'initialisation. Du coup, on les redéfinit à la main. + """ + + default_error_messages = { + "required": _("Veuillez vérifier que vous êtes bien humain·e."), + "error_hcaptcha": _("Erreur lors de la vérification."), + "invalid_hcaptcha": _("Échec de la vérification !"), + } + + class DemandeForm(ModelForm): - captcha = ReCaptchaField(attrs={"theme": "clean", "lang": "fr"}) + captcha = hCaptchaFieldWithErrors() def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) diff --git a/requirements.txt b/requirements.txt index 565d2b71..8baaa5ed 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,7 +3,7 @@ Django==2.2.* django-autocomplete-light==3.3.* django-cas-ng==3.6.* django-djconfig==0.8.0 -django-recaptcha==1.4.0 +django-hCaptcha==0.1.0 icalendar Pillow django-bootstrap-form==3.3