Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions math_captcha/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,18 @@ def math_clean(form):
assert len(test_secret) == 40 and question
except (TypeError, AssertionError):
# problem decoding, junky data
raise forms.ValidationError('Invalid token')
form._errors['math_captcha_field'] = form.error_class(["Invalid token"])
del form.cleaned_data['math_captcha_field']
except KeyError:
return

if encode(question) != form.cleaned_data['math_captcha_question']:
# security problem, hack attempt
raise forms.ValidationError('Invalid token')
form._errors['math_captcha_field'] = form.error_class(["Invalid token"])
del form.cleaned_data['math_captcha_field']
if eval(question) != value:
raise forms.ValidationError('Wrong answer, try again')

form._errors['math_captcha_field'] = form.error_class(["Wrong answer, try again"])
del form.cleaned_data['math_captcha_field']

class MathCaptchaModelForm(forms.ModelForm):
"""
Expand Down