forked from DGNum/gestioCOF
Merge branch 'Aufinal/hcaptcha' into 'master'
Remplace recaptcha par hcaptcha Closes #262 See merge request klub-dev-ens/gestioCOF!497
This commit is contained in:
commit
c71e6d22bf
6 changed files with 33 additions and 21 deletions
|
@ -23,6 +23,10 @@ adhérents ni des cotisations.
|
|||
|
||||
## Version ??? - dans un futur proche
|
||||
|
||||
### TODO Prod
|
||||
|
||||
- Créer un compte hCaptcha (https://www.hcaptcha.com/), au COF, et remplacer les secrets associés
|
||||
|
||||
### K-Fêt
|
||||
|
||||
- L'accès à l'historique est maintenant limité à 7 jours pour raison de confidentialité. Les chefs/trez peuvent disposer d'une permission supplémentaire pour accèder à jusqu'à 30 jours en cas de problème de compta. L'accès à son historique personnel n'est pas limité. Les durées sont configurables dans `settings/cof_prod.py`.
|
||||
|
|
|
@ -26,8 +26,8 @@ REDIS_DB = import_secret("REDIS_DB")
|
|||
REDIS_HOST = import_secret("REDIS_HOST")
|
||||
REDIS_PORT = import_secret("REDIS_PORT")
|
||||
|
||||
RECAPTCHA_PUBLIC_KEY = import_secret("RECAPTCHA_PUBLIC_KEY")
|
||||
RECAPTCHA_PRIVATE_KEY = import_secret("RECAPTCHA_PRIVATE_KEY")
|
||||
HCAPTCHA_SITEKEY = import_secret("HCAPTCHA_SITEKEY")
|
||||
HCAPTCHA_SECRET = import_secret("HCAPTCHA_SECRET")
|
||||
KFETOPEN_TOKEN = import_secret("KFETOPEN_TOKEN")
|
||||
|
||||
# ---
|
||||
|
@ -50,7 +50,7 @@ INSTALLED_APPS = (
|
|||
+ [
|
||||
"bda",
|
||||
"petitscours",
|
||||
"captcha",
|
||||
"hcaptcha",
|
||||
"kfet",
|
||||
"kfet.open",
|
||||
"channels",
|
||||
|
|
|
@ -16,8 +16,8 @@ REDIS_PORT = 6379
|
|||
REDIS_DB = 0
|
||||
REDIS_HOST = "127.0.0.1"
|
||||
|
||||
RECAPTCHA_PUBLIC_KEY = "DUMMY"
|
||||
RECAPTCHA_PRIVATE_KEY = "DUMMY"
|
||||
HCAPTCHA_SITEKEY = "10000000-ffff-ffff-ffff-000000000001"
|
||||
HCAPTCHA_SECRET = "0x0000000000000000000000000000000000000000"
|
||||
|
||||
EMAIL_HOST = None
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import json
|
||||
import os
|
||||
from unittest import mock
|
||||
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.test import TestCase
|
||||
|
@ -257,18 +257,15 @@ class PetitCoursDemandeViewTestCase(ViewTestCaseMixin, TestCase):
|
|||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
os.environ["RECAPTCHA_TESTING"] = "True"
|
||||
self.subject1 = create_petitcours_subject()
|
||||
self.subject2 = create_petitcours_subject()
|
||||
|
||||
def tearDown(self):
|
||||
os.environ["RECAPTCHA_TESTING"] = "False"
|
||||
|
||||
def test_get(self):
|
||||
resp = self.client.get(self.url)
|
||||
self.assertEqual(resp.status_code, 200)
|
||||
|
||||
def test_post(self):
|
||||
@mock.patch("hcaptcha.fields.hCaptchaField.clean")
|
||||
def test_post(self, mock_clean):
|
||||
data = {
|
||||
"name": "Le nom",
|
||||
"email": "lemail@mail.net",
|
||||
|
@ -280,7 +277,7 @@ class PetitCoursDemandeViewTestCase(ViewTestCaseMixin, TestCase):
|
|||
"agrege_requis": "1",
|
||||
"niveau": "lycee",
|
||||
"remarques": "no comment",
|
||||
"g-recaptcha-response": "PASSED",
|
||||
"h-captcha-response": 1,
|
||||
}
|
||||
resp = self.client.post(self.url, data)
|
||||
|
||||
|
@ -299,18 +296,15 @@ class PetitCoursDemandeRawViewTestCase(ViewTestCaseMixin, TestCase):
|
|||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
os.environ["RECAPTCHA_TESTING"] = "True"
|
||||
self.subject1 = create_petitcours_subject()
|
||||
self.subject2 = create_petitcours_subject()
|
||||
|
||||
def tearDown(self):
|
||||
os.environ["RECAPTCHA_TESTING"] = "False"
|
||||
|
||||
def test_get(self):
|
||||
resp = self.client.get(self.url)
|
||||
self.assertEqual(resp.status_code, 200)
|
||||
|
||||
def test_post(self):
|
||||
@mock.patch("hcaptcha.fields.hCaptchaField.clean")
|
||||
def test_post(self, mock_clean):
|
||||
data = {
|
||||
"name": "Le nom",
|
||||
"email": "lemail@mail.net",
|
||||
|
@ -322,7 +316,7 @@ class PetitCoursDemandeRawViewTestCase(ViewTestCaseMixin, TestCase):
|
|||
"agrege_requis": "1",
|
||||
"niveau": "lycee",
|
||||
"remarques": "no comment",
|
||||
"g-recaptcha-response": "PASSED",
|
||||
"h-captcha-response": 1,
|
||||
}
|
||||
resp = self.client.post(self.url, data)
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue