Show
Ignore:
Timestamp:
07/09/2008 03:45:47 PM (5 months ago)
Author:
Geert
Message:

Revamped Captcha library big time.

  • Each Captcha style has its own driver which generates and renders a Captcha challenge. The output could be an image, but could be anything else since html output is allowed. I included a Riddle driver to give you an idea of the flexibility.
  • Config groups supported.
  • More polished coding style and structure in general.
  • Still needs work on the image generating part. Mostly GD2 stuff, and quite some copy and paste from the previous version. Any help appreciated. :)
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/system/controllers/captcha.php

    r3010 r3015  
    11<?php defined('SYSPATH') or die('No direct script access.'); 
    22/** 
    3  * Allows a CAPTCHA image to be displayed dynamically. 
    4  * Captcha library is called to output the image. 
    5  * 
    6  * 
    7  * Usage: Call the captcha controller from a view. 
    8  *        `echo html::image(url::site().'captcha');` 
     3 * Outputs the dynamic Captcha image. 
     4 * Usage: Call the Captcha controller from a view, e.g. 
     5 *        <img src="<?php echo url::site('captcha') ?>" /> 
    96 * 
    107 * $Id$ 
    118 * 
    12  * @package    Core 
     9 * @package    Captcha 
    1310 * @author     Kohana Team 
    1411 * @copyright  (c) 2007-2008 Kohana Team 
     
    1714class Captcha_Controller extends Controller { 
    1815 
    19         public $session; 
    20         public $captcha; 
    21  
    22         protected $captcha_code; 
    23  
    2416        public function index() 
    2517        { 
    26                 $this->session = Session::instance(); 
    27                 $this->captcha = new Captcha; 
    28  
    29                 // Create and store a random captcha string 
    30                 $this->captcha_code = $this->create_code(); 
    31                 $this->captcha->set_code($this->captcha_code); 
    32                 $this->session->set('captcha_code', $this->captcha_code); 
    33  
    34                 // Output the image 
    35                 $this->captcha->render(); 
    36         } 
    37  
    38         private function create_code() 
    39         { 
    40                 if (Config::item('captcha.style') === 'math') 
    41                 { 
    42                         $code = (string) mt_rand(101, 991); 
    43                 } 
    44                 else 
    45                 { 
    46                         $code = text::random('distinct', Config::item('captcha.num_chars')); 
    47                 } 
    48  
    49                 return $code; 
     18                // Output the Captcha challenge resource (no html) 
     19                $captcha = new Captcha; 
     20                $captcha->render(FALSE); 
    5021        } 
    5122