google-code-export / django-simple-captcha

Automatically exported from code.google.com/p/django-simple-captcha
MIT License
0 stars 0 forks source link

Captcha is not compatible with formwizard #4

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create formwizard (from django.contrib)
2. Put captcha into one of the forms in this wizard
3. Captcha does not get validated

What is the expected output? What do you see instead?
I expect captcha to pass but it never happens

What version of the product are you using? On what operating system?
Version: 1.1 alpha 1 SVN-9975 latest django-simple-captcha from SVN

Please provide any additional information below.
FormWizard does validation twice (after form submission and after the last
step), but the record gets deleted after the 1st validation, so maybe its
possible to store validation result for reuse...

Original issue reported on code.google.com by qri...@gmail.com on 5 Apr 2009 at 8:44

GoogleCodeExporter commented 9 years ago
I've never used the formwizard contrib, but will definitely give it a try and 
see how
I can fix DSC to work with it, though.

Original comment by mbonetti on 27 Apr 2009 at 2:31

GoogleCodeExporter commented 9 years ago
Actually I'm not sure if the problem is in captcha itself. I've filed a ticket -
http://code.djangoproject.com/ticket/10810 but the solution proposed is a 
work-around
and I haven't found how to combine "one-way" fields with formwizard. It looks 
like
conflicting requirements (revalidation in formwizard and single validation in 
captcha)

Original comment by qri...@gmail.com on 27 Apr 2009 at 2:38

GoogleCodeExporter commented 9 years ago
A quick-fix would probably be to comment-out the store.delete() line on line 58 
of
fields.py, and configure a large-enough CAPTCHA_TIMEOUT period, so that the 
captcha
can be validated an unlimited numbed of times, during the validity period.

Original comment by mbonetti on 27 Apr 2009 at 2:48

GoogleCodeExporter commented 9 years ago
Of course, but I don't think it's the right way to do it...

Original comment by qri...@gmail.com on 27 Apr 2009 at 3:56

GoogleCodeExporter commented 9 years ago
My approach was to inherit my own FormWizard class from the one provided
in django.contrib.formtools.

My derived class implements its own __call__() method, which is basicaly 
cut'n'pasted
from django with small difference, see following patch:

--- /tmp/modified.py    2011-02-03 01:10:20.000000000 +0100
+++ /tmp/original.py    2011-02-03 01:11:16.000000000 +0100
@@ -41,7 +41,7 @@
                 # must mean the validator relied on some other input, such as
                 # an external Web site.
                 for i, f in enumerate(final_form_list):
-                    if not f.is_valid() and not self.has_captcha_field(f):
+                    if not f.is_valid():
                         return self.render_revalidation_failure(request, i, f)
                 return self.done(request, final_form_list)

@@ -51,4 +51,3 @@
                 self.step = current_step = next_step

         return self.render(form, request, current_step)

the derived class also implements a static method has_captcha_field(),
which looks as follows:
    @staticmethod
    def has_captcha_field(form):
        for f in form.fields:
            if type(form[f].field) == type(CaptchaField()):
                return True
        return False

it works for me pretty well.

Original comment by anedvedi...@gmail.com on 3 Feb 2011 at 12:16

GoogleCodeExporter commented 9 years ago
My workaround has been call "storage.delete()" at the method "__delete__" of 
the field class, this way the field can be cleaned more than once in the 
context of the same instance and not in multiple requests.

Original comment by anle...@gmail.com on 1 Apr 2011 at 11:23

Attachments: