feat: Add captcha to registration
This commit is contained in:
parent
7a80cf8df1
commit
05178da029
@ -9,6 +9,14 @@ from django.utils.translation import gettext_lazy as _
|
|||||||
from notfellchen.settings import MEDIA_URL
|
from notfellchen.settings import MEDIA_URL
|
||||||
|
|
||||||
|
|
||||||
|
def animal_validator(value: str):
|
||||||
|
value = value.lower()
|
||||||
|
animal_list = ["ratte", "farbratte", "katze", "hund", "kaninchen", "hase", "kuh", "fuchs", "cow", "rat", "cat",
|
||||||
|
"dog", "rabbit", "fox"]
|
||||||
|
if value not in animal_list:
|
||||||
|
raise forms.ValidationError(_("Dieses Tier kenne ich nicht. Probier ein anderes"))
|
||||||
|
|
||||||
|
|
||||||
class DateInput(forms.DateInput):
|
class DateInput(forms.DateInput):
|
||||||
input_type = 'date'
|
input_type = 'date'
|
||||||
|
|
||||||
@ -62,7 +70,6 @@ class AdoptionNoticeFormWithDateWidget(AdoptionNoticeForm):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class AnimalForm(forms.ModelForm):
|
class AnimalForm(forms.ModelForm):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
if 'in_adoption_notice_creation_flow' in kwargs:
|
if 'in_adoption_notice_creation_flow' in kwargs:
|
||||||
@ -91,6 +98,7 @@ class AnimalFormWithDateWidget(AnimalForm):
|
|||||||
'date_of_birth': DateInput(),
|
'date_of_birth': DateInput(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class AdoptionNoticeFormWithDateWidgetAutoAnimal(AdoptionNoticeFormWithDateWidget):
|
class AdoptionNoticeFormWithDateWidgetAutoAnimal(AdoptionNoticeFormWithDateWidget):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(AdoptionNoticeFormWithDateWidgetAutoAnimal, self).__init__(*args, **kwargs)
|
super(AdoptionNoticeFormWithDateWidgetAutoAnimal, self).__init__(*args, **kwargs)
|
||||||
@ -159,6 +167,8 @@ class CustomRegistrationForm(RegistrationForm):
|
|||||||
class Meta(RegistrationForm.Meta):
|
class Meta(RegistrationForm.Meta):
|
||||||
model = User
|
model = User
|
||||||
|
|
||||||
|
captcha = forms.CharField(validators=[animal_validator], label=_("Nenne ein Tier (Captcha)"))
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
self.helper = FormHelper()
|
self.helper = FormHelper()
|
||||||
@ -169,7 +179,7 @@ class CustomRegistrationForm(RegistrationForm):
|
|||||||
|
|
||||||
|
|
||||||
def _get_distances():
|
def _get_distances():
|
||||||
return {i: i for i in [10, 20, 50, 100, 200, 500]}
|
return {i: i for i in [20, 50, 100, 200, 500]}
|
||||||
|
|
||||||
|
|
||||||
class AdoptionNoticeSearchForm(forms.Form):
|
class AdoptionNoticeSearchForm(forms.Form):
|
||||||
|
Loading…
Reference in New Issue
Block a user