Remplace recaptcha par hcaptcha

This commit is contained in:
Ludovic Stephan 2021-03-04 17:56:42 +01:00
parent 2350109a33
commit 47dd078b6a
3 changed files with 18 additions and 4 deletions

View file

@ -50,7 +50,7 @@ INSTALLED_APPS = (
+ [
"bda",
"petitscours",
"captcha",
"hcaptcha",
"kfet",
"kfet.open",
"channels",

View file

@ -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)

View file

@ -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