Changeset 3047 for trunk/application

Show
Ignore:
Timestamp:
07/11/2008 07:14:01 AM (5 months ago)
Author:
Geert
Message:

Captcha updates:

  • Bug fix: made sure the captcha_response session cannot be overwritten too soon. The problem was that Captcha::valid() would break if you created a new Captcha instance before it. Another good example of the power of Kohana events.
  • Added a static instance() method so Captcha::valid() can access non-static methods, e.g. the counters.
  • Shortened method names a bit: from "valid_response" to "valid", same for counters.
  • Added a reset_count() method.
  • Updated the example.
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/application/controllers/examples.php

    r3043 r3047  
    178178                new Profiler; 
    179179 
    180                 // Ban bots after 10 invalid responses 
     180                // Load Captcha library 
     181                $captcha = new Captcha; 
     182 
     183                // Ban bots (that accept session cookies) after 50 invalid responses 
    181184                // Be careful not to ban real people though! Set the threshold high enough. 
    182                 if (Captcha::invalid_response_count() > 9) 
     185                if ($captcha->invalid_count() > 49) 
    183186                        exit('Bye! Stupid bot.'); 
    184187 
     
    187190                { 
    188191                        // User has not given three valid responses yet 
    189                         if (Captcha::valid_response_count() < 3) 
     192                        if ($captcha->valid_count() < 3) 
    190193                        { 
    191                                 // Valid response has been submitted 
    192                                 if (Captcha::valid_response($this->input->post('captcha_response'))) 
     194                                // Captcha::valid() is a static method that can be used as a Validation rule also 
     195                                if (Captcha::valid($this->input->post('captcha_response'))) 
    193196                                { 
    194197                                        echo '<p style="color:green">Good answer!</p>'; 
     
    208211 
    209212                // Don't show Captcha anymore after three or more valid responses 
    210                 if (Captcha::valid_response_count() < 3) 
     213                if ($captcha->valid_count() < 3) 
    211214                { 
    212215                        echo '<p>'; 
    213                         echo Captcha::factory()->render(); // Shows the Captcha challenge (image/riddle/etc) 
     216                        echo $captcha->render(); // Shows the Captcha challenge (image/riddle/etc) 
    214217                        echo '</p>'; 
    215218                        echo form::input('captcha_response');