Mercurial > public > sg101
diff gpp/accounts/forms.py @ 347:69d0306a6fe7
Fixing #165: add a way to filter users in the admin by join date; add an admin action to approve a pending user; added a honeypot type field to the registration form.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Wed, 02 Mar 2011 01:11:32 +0000 |
parents | efa3b4901777 |
children | 7c3816d76c6c |
line wrap: on
line diff
--- a/gpp/accounts/forms.py Mon Feb 28 03:53:04 2011 +0000 +++ b/gpp/accounts/forms.py Wed Mar 02 01:11:32 2011 +0000 @@ -19,7 +19,7 @@ """Form used to register with the website""" username = forms.RegexField(max_length=30, regex=r'^\w+$', error_messages={ - 'invalid': 'Your username must be 30 characters or less and ' \ + 'invalid': 'Your username must be 30 characters or less and ' 'contain only letters, numbers and underscores.'}) email = forms.EmailField() password1 = forms.CharField(label="Password", widget=forms.PasswordInput) @@ -27,7 +27,7 @@ agree_age = forms.BooleanField(required=True, label='I certify that I am over the age of 13', error_messages={ - 'required': 'Sorry, but you must be over the age of 13 to ' \ + 'required': 'Sorry, but you must be over the age of 13 to ' 'register at our site.', }) agree_tos = forms.BooleanField(required=True, @@ -41,6 +41,8 @@ 'required': 'You have not agreed to our Privacy Policy.', }) question1 = forms.CharField(label="What number appears in the site name?") + question2 = forms.CharField(label='', required=False, + widget=forms.TextInput(attrs={'style': 'display: none;'})) def __init__(self, *args, **kwargs): self.ip = kwargs.pop('ip', '?') @@ -101,6 +103,15 @@ self._validation_error("Incorrect answer to our anti-spam question.", answer) return answer + def clean_question2(self): + """ + Honeypot field should be empty. + """ + answer = self.cleaned_data.get('question2') + if answer: + self._validation_error('Wrong answer #2: %s' % answer) + return answer + def save(self): pending_user = PendingUser.objects.create_pending_user(self.cleaned_data['username'], self.cleaned_data['email'],