Changeset 3080 for trunk/application

Show
Ignore:
Timestamp:
07/11/2008 01:30:46 PM (5 months ago)
Author:
Geert
Message:

Added a promote config setting for Captcha which basically means after how many valid responses you want to promote a user to human. As soon as a user has been promoted Captcha responses will automatically validate. The only thing you should add in your controller or view is a check that hides the Captcha field if the user has been promoted. I updated the examples controller as well.

Files:
1 modified

Legend:

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

    r3047 r3080  
    175175        public function captcha() 
    176176        { 
    177                 // Look at the counters in the Session Profiler 
     177                // Look at the counters for valid and invalid 
     178                // responses in the Session Profiler. 
    178179                new Profiler; 
    179180 
    180                 // Load Captcha library 
     181                // Load Captcha library, you can supply the name 
     182                // of the config group you would like to use. 
    181183                $captcha = new Captcha; 
    182184 
    183                 // Ban bots (that accept session cookies) after 50 invalid responses 
     185                // Ban bots (that accept session cookies) after 50 invalid responses. 
    184186                // Be careful not to ban real people though! Set the threshold high enough. 
    185187                if ($captcha->invalid_count() > 49) 
     
    189191                if ($_POST) 
    190192                { 
    191                         // User has not given three valid responses yet 
    192                         if ($captcha->valid_count() < 3) 
     193                        // Captcha::valid() is a static method that can be used as a Validation rule also. 
     194                        if (Captcha::valid($this->input->post('captcha_response'))) 
    193195                        { 
    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'))) 
    196                                 { 
    197                                         echo '<p style="color:green">Good answer!</p>'; 
    198                                 } 
    199                                 else 
    200                                 { 
    201                                         echo '<p style="color:red">Wrong answer!</p>'; 
    202                                 } 
     196                                echo '<p style="color:green">Good answer!</p>'; 
    203197                        } 
     198                        else 
     199                        { 
     200                                echo '<p style="color:red">Wrong answer!</p>'; 
     201                        } 
    204202 
    205203                        // Validate other fields here 
    206204                } 
    207205 
    208                 // Open form 
     206                // Show form 
    209207                echo form::open(); 
    210208                echo '<p>Other form fields here...</p>'; 
    211209 
    212                 // Don't show Captcha anymore after three or more valid responses 
    213                 if ($captcha->valid_count() < 3) 
     210                // Don't show Captcha anymore after the user has given enough valid 
     211                // responses. The "enough" count is set in the captcha config. 
     212                if ( ! $captcha->promoted()) 
    214213                { 
    215214                        echo '<p>'; 
     
    217216                        echo '</p>'; 
    218217                        echo form::input('captcha_response'); 
     218                } 
     219                else 
     220                { 
     221                        echo '<p>You have been promoted to human.</p>'; 
    219222                } 
    220223