Mercurial > public > sg101
comparison accounts/forms.py @ 782:9133b4626a4b
Added additional security questions on the registration page.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Tue, 13 May 2014 19:44:48 -0500 |
parents | 988782c6ce6c |
children | f416f5db3d91 |
comparison
equal
deleted
inserted
replaced
781:b6d6c9e37fae | 782:9133b4626a4b |
---|---|
50 }) | 50 }) |
51 question1 = forms.CharField(label="What number appears in the site name?", | 51 question1 = forms.CharField(label="What number appears in the site name?", |
52 widget=forms.TextInput(attrs={'class': 'text'})) | 52 widget=forms.TextInput(attrs={'class': 'text'})) |
53 question2 = forms.CharField(label='', required=False, | 53 question2 = forms.CharField(label='', required=False, |
54 widget=forms.TextInput(attrs={'style': 'display: none;'})) | 54 widget=forms.TextInput(attrs={'style': 'display: none;'})) |
55 question3 = forms.CharField(label="Don't put anything in this box", | |
56 required=False, | |
57 widget=forms.TextInput(attrs={'class': 'text'})) | |
58 | |
59 SPAM_CHOICES = [(1, 'cat'), (2, '328'), (4, 'green'), (8, 'ocean')] | |
60 question4 = forms.ChoiceField(label="Pick the number", choices=SPAM_CHOICES) | |
61 question5 = forms.IntegerField(label="What number did you pick, above?", | |
62 widget=forms.TextInput(attrs={'class': 'text'})) | |
63 question6 = forms.ChoiceField(label="Pick the color", choices=SPAM_CHOICES) | |
64 | |
65 USER_QUALITIES = [ | |
66 (1, "I am the lowest form of life, a spammer"), | |
67 (2, "I'm a fan of surf music or I want to learn more"), | |
68 (3, "Someone is paying me to post links to this site"), | |
69 (4, "I am not going to spam this site"), | |
70 (5, "I understand my account may be removed if I post spam"), | |
71 (6, "I am going to spam the crap out of this site"), | |
72 (7, "Surf music is one of my interests, not spam"), | |
73 ] | |
74 question7 = forms.MultipleChoiceField( | |
75 label="Check all that apply", | |
76 choices=USER_QUALITIES, | |
77 required=False, | |
78 widget=forms.CheckboxSelectMultiple) | |
79 | |
55 | 80 |
56 def __init__(self, *args, **kwargs): | 81 def __init__(self, *args, **kwargs): |
57 self.ip = kwargs.pop('ip', '?') | 82 self.ip = kwargs.pop('ip', '?') |
58 super(RegisterForm, self).__init__(*args, **kwargs) | 83 super(RegisterForm, self).__init__(*args, **kwargs) |
59 | 84 |
117 if answer: | 142 if answer: |
118 logger.critical('Accounts/registration: Honeypot filled [%s]', self.ip) | 143 logger.critical('Accounts/registration: Honeypot filled [%s]', self.ip) |
119 self._validation_error('Wrong answer #2', answer) | 144 self._validation_error('Wrong answer #2', answer) |
120 return answer | 145 return answer |
121 | 146 |
147 def clean_question3(self): | |
148 answer = self.cleaned_data.get('question3') | |
149 if answer: | |
150 self._validation_error('Oops, that should be blank', answer) | |
151 return answer | |
152 | |
153 def clean_question4(self): | |
154 answer = self.cleaned_data.get('question4') | |
155 if answer != u'2': | |
156 self._validation_error('Please pick the number', answer) | |
157 return answer | |
158 | |
159 def clean_question5(self): | |
160 answer = self.cleaned_data.get('question5') | |
161 if answer != 328: | |
162 self._validation_error('Please enter the correct number', answer) | |
163 return answer | |
164 | |
165 def clean_question6(self): | |
166 answer = self.cleaned_data.get('question6') | |
167 if answer != u'4': | |
168 self._validation_error('Please pick the color', answer) | |
169 return answer | |
170 | |
171 def clean_question7(self): | |
172 answer = self.cleaned_data.get('question7') | |
173 answer.sort() | |
174 if answer != [u'2', u'4', u'5', u'7']: | |
175 self._validation_error("Sorry, try again", answer) | |
176 return answer | |
177 | |
122 def save(self): | 178 def save(self): |
123 pending_user = PendingUser.objects.create_pending_user(self.cleaned_data['username'], | 179 pending_user = PendingUser.objects.create_pending_user(self.cleaned_data['username'], |
124 self.cleaned_data['email'], | 180 self.cleaned_data['email'], |
125 self.cleaned_data['password1']) | 181 self.cleaned_data['password1']) |
126 | 182 |