some fixes, honeypot registration
This commit is contained in:
@@ -20,6 +20,7 @@ from django.contrib.admin.widgets import AdminDateWidget
|
||||
from django.forms.widgets import SelectDateWidget, HiddenInput
|
||||
from django_recaptcha.fields import ReCaptchaField
|
||||
from django_recaptcha.widgets import ReCaptchaV3
|
||||
from django.core.exceptions import ValidationError
|
||||
|
||||
from django.utils import timezone, translation
|
||||
from django.forms import ModelForm, Select
|
||||
@@ -1015,6 +1016,25 @@ class RegistrationFormUniqueEmail(RegistrationFormTermsOfService):
|
||||
"This email address is already in use. Please supply a different email address.")
|
||||
return self.cleaned_data['email']
|
||||
|
||||
class HoneypotField(forms.CharField):
|
||||
"""
|
||||
A honeypot field that should be left empty by humans
|
||||
"""
|
||||
def __init__(self, *args, **kwargs):
|
||||
kwargs.setdefault('required', False)
|
||||
kwargs.setdefault('widget', forms.TextInput(attrs={
|
||||
'style': 'display:none !important',
|
||||
'tabindex': '-1',
|
||||
'autocomplete': 'off',
|
||||
'aria-hidden': 'true',
|
||||
}))
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
def clean(self, value):
|
||||
if value:
|
||||
# If the field has a value, it's likely a bot
|
||||
raise ValidationError("Please leave this field empty.")
|
||||
return value
|
||||
|
||||
class RegistrationFormSex(RegistrationFormUniqueEmail):
|
||||
sexcategories = (
|
||||
@@ -1037,7 +1057,9 @@ class RegistrationFormSex(RegistrationFormUniqueEmail):
|
||||
initial=datetime.date(year=1970,
|
||||
month=4,
|
||||
day=15))
|
||||
|
||||
|
||||
url = HoneypotField(label="URL")
|
||||
|
||||
def clean_birthdate(self):
|
||||
dob = self.cleaned_data['birthdate']
|
||||
age = (timezone.now() - dob).days/365
|
||||
|
||||
Reference in New Issue
Block a user