comparison 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
comparison
equal deleted inserted replaced
346:efa3b4901777 347:69d0306a6fe7
17 17
18 class RegisterForm(forms.Form): 18 class RegisterForm(forms.Form):
19 """Form used to register with the website""" 19 """Form used to register with the website"""
20 username = forms.RegexField(max_length=30, regex=r'^\w+$', 20 username = forms.RegexField(max_length=30, regex=r'^\w+$',
21 error_messages={ 21 error_messages={
22 'invalid': 'Your username must be 30 characters or less and ' \ 22 'invalid': 'Your username must be 30 characters or less and '
23 'contain only letters, numbers and underscores.'}) 23 'contain only letters, numbers and underscores.'})
24 email = forms.EmailField() 24 email = forms.EmailField()
25 password1 = forms.CharField(label="Password", widget=forms.PasswordInput) 25 password1 = forms.CharField(label="Password", widget=forms.PasswordInput)
26 password2 = forms.CharField(label="Password confirmation", widget=forms.PasswordInput) 26 password2 = forms.CharField(label="Password confirmation", widget=forms.PasswordInput)
27 agree_age = forms.BooleanField(required=True, 27 agree_age = forms.BooleanField(required=True,
28 label='I certify that I am over the age of 13', 28 label='I certify that I am over the age of 13',
29 error_messages={ 29 error_messages={
30 'required': 'Sorry, but you must be over the age of 13 to ' \ 30 'required': 'Sorry, but you must be over the age of 13 to '
31 'register at our site.', 31 'register at our site.',
32 }) 32 })
33 agree_tos = forms.BooleanField(required=True, 33 agree_tos = forms.BooleanField(required=True,
34 label='I agree to the Terms of Service', 34 label='I agree to the Terms of Service',
35 error_messages={ 35 error_messages={
39 label='I agree to the Privacy Policy', 39 label='I agree to the Privacy Policy',
40 error_messages={ 40 error_messages={
41 'required': 'You have not agreed to our Privacy Policy.', 41 'required': 'You have not agreed to our Privacy Policy.',
42 }) 42 })
43 question1 = forms.CharField(label="What number appears in the site name?") 43 question1 = forms.CharField(label="What number appears in the site name?")
44 question2 = forms.CharField(label='', required=False,
45 widget=forms.TextInput(attrs={'style': 'display: none;'}))
44 46
45 def __init__(self, *args, **kwargs): 47 def __init__(self, *args, **kwargs):
46 self.ip = kwargs.pop('ip', '?') 48 self.ip = kwargs.pop('ip', '?')
47 super(RegisterForm, self).__init__(*args, **kwargs) 49 super(RegisterForm, self).__init__(*args, **kwargs)
48 50
99 success = val == 101 101 success = val == 101
100 if not success: 102 if not success:
101 self._validation_error("Incorrect answer to our anti-spam question.", answer) 103 self._validation_error("Incorrect answer to our anti-spam question.", answer)
102 return answer 104 return answer
103 105
106 def clean_question2(self):
107 """
108 Honeypot field should be empty.
109 """
110 answer = self.cleaned_data.get('question2')
111 if answer:
112 self._validation_error('Wrong answer #2: %s' % answer)
113 return answer
114
104 def save(self): 115 def save(self):
105 pending_user = PendingUser.objects.create_pending_user(self.cleaned_data['username'], 116 pending_user = PendingUser.objects.create_pending_user(self.cleaned_data['username'],
106 self.cleaned_data['email'], 117 self.cleaned_data['email'],
107 self.cleaned_data['password1']) 118 self.cleaned_data['password1'])
108 119