comparison gpp/accounts/forms.py @ 472:7c3816d76c6c

Implement rate limiting on registration and login for #224.
author Brian Neal <bgneal@gmail.com>
date Thu, 25 Aug 2011 02:23:55 +0000
parents 69d0306a6fe7
children b137a0966e4b
comparison
equal deleted inserted replaced
471:d83296cac940 472:7c3816d76c6c
11 11
12 from core.functions import send_mail 12 from core.functions import send_mail
13 from accounts.models import PendingUser 13 from accounts.models import PendingUser
14 from accounts.models import IllegalUsername 14 from accounts.models import IllegalUsername
15 from accounts.models import IllegalEmail 15 from accounts.models import IllegalEmail
16 from antispam.rate_limit import block_ip
16 17
17 18
18 class RegisterForm(forms.Form): 19 class RegisterForm(forms.Form):
19 """Form used to register with the website""" 20 """Form used to register with the website"""
20 username = forms.RegexField(max_length=30, regex=r'^\w+$', 21 username = forms.RegexField(max_length=30, regex=r'^\w+$',
107 """ 108 """
108 Honeypot field should be empty. 109 Honeypot field should be empty.
109 """ 110 """
110 answer = self.cleaned_data.get('question2') 111 answer = self.cleaned_data.get('question2')
111 if answer: 112 if answer:
113 block_ip(self.ip)
112 self._validation_error('Wrong answer #2: %s' % answer) 114 self._validation_error('Wrong answer #2: %s' % answer)
113 return answer 115 return answer
114 116
115 def save(self): 117 def save(self):
116 pending_user = PendingUser.objects.create_pending_user(self.cleaned_data['username'], 118 pending_user = PendingUser.objects.create_pending_user(self.cleaned_data['username'],