Development

HowToCaptcha (diff)

You must first sign up to be able to contribute.

Changes from Version 1 of HowToCaptcha

Show
Ignore:
Author:
pookey@pookey.co.uk (IP: 81.6.197.68)
Timestamp:
03/26/06 00:10:53 (12 years ago)
Comment:

created

Legend:

Unmodified
Added
Removed
Modified
  • HowToCaptcha

    v0 v1  
     1I don't do documenation well - here's the code to use jpgraphs stuff - someone else will need to write more details here about installing it, where to put files etc. etc. 
     2 
     3action: 
     4{{{ 
     5 
     6class profileActions extends sfActions 
     7{ 
     8 
     9  public function executeRegister() 
     10  {    
     11      if ($this->getRequest()->getMethod() == sfRequest::POST) { 
     12          // process form 
     13      } 
     14      require_once 'jpgraph/jpgraph_antispam.php'; 
     15      $antispam = new AntiSpam(); 
     16      $antispam_string = $antispam->rand(5); 
     17      $this->getUser()->setAttribute('antispam', $antispam_string); 
     18  } 
     19 
     20  public function executeAntispam() { 
     21      if (!$string = $this->getUser()->getAttribute('antispam')) { 
     22          return sfView::NONE; 
     23      } 
     24 
     25      require_once 'jpgraph/jpgraph_antispam.php'; 
     26      $this->getResponse()->setContentType('image/jpeg'); 
     27      $antispam = new AntiSpam($string); 
     28      echo $antispam->stroke(); 
     29      return sfView::NONE; 
     30  } 
     31} 
     32}}} 
     33 
     34view: 
     35 
     36{{{ 
     37        <label>Picture</label> 
     38        <img src="<?php echo url_for('profile/antispam'); ?>" /> 
     39        <br /> 
     40}}} 
     41 
     42 
     43validator: myCharactersValidator.class.php 
     44 
     45{{{ 
     46  class myCharactersValidator extends sfValidator 
     47  { 
     48      public function execute (&$value, &$error) 
     49      { 
     50          $string = sfContext::getInstance()->getUser()->getAttribute('antispam'); 
     51          if ($value != $string) { 
     52 
     53              // generate a new image.... 
     54              require_once 'jpgraph/jpgraph_antispam.php'; 
     55              $antispam = new AntiSpam(); 
     56              $antispam_string = $antispam->rand(5); 
     57              sfContext::getInstance()->getUser()->setAttribute('antispam', $antispam_string); 
     58 
     59              $error = $this->getParameter('characters_error'); 
     60              return false; 
     61          }        
     62          return true; 
     63      } 
     64  } 
     65 
     66}}}