Index: branches/RC/themes/default2007/platform/elements/forms.tpl =================================================================== diff -u -N -r9720 -r10539 --- branches/RC/themes/default2007/platform/elements/forms.tpl (.../forms.tpl) (revision 9720) +++ branches/RC/themes/default2007/platform/elements/forms.tpl (.../forms.tpl) (revision 10539) @@ -312,6 +312,21 @@ + + "> + + + +
+
+ " alt=""/>
+ img/s.gif" width="1" height="5" alt=""/>
+ " value="" tabindex="" style=""> + + + +
+ "> Index: branches/RC/core/units/users/users_config.php =================================================================== diff -u -N -r10517 -r10539 --- branches/RC/core/units/users/users_config.php (.../users_config.php) (revision 10517) +++ branches/RC/core/units/users/users_config.php (.../users_config.php) (revision 10539) @@ -56,6 +56,29 @@ 'DoSpecial' => '*', 'DoEvent' => 'OnAutoLoginUser', ), + + // Captcha processing + Array ( + 'Mode' => hAFTER, + 'Conditional' => false, + 'HookToPrefix' => '', + 'HookToSpecial' => '*', + 'HookToEvent' => Array('OnAfterConfigRead'), + 'DoPrefix' => 'captcha', + 'DoSpecial' => '*', + 'DoEvent' => 'OnPrepareCaptcha', + ), + + /*Array ( + 'Mode' => hAFTER, + 'Conditional' => false, + 'HookToPrefix' => '', + 'HookToSpecial' => '*', + 'HookToEvent' => Array('OnBeforeItemCreate'), + 'DoPrefix' => 'captcha', + 'DoSpecial' => '*', + 'DoEvent' => 'OnValidateCode', + ),*/ ), 'QueryString' => Array( @@ -222,7 +245,6 @@ 'ValidateLogin' => Array('type'=>'string','default'=>''), 'SubscribeEmail' => Array('type'=>'string','default'=>''), 'PrimaryGroup' => Array('type' => 'string', 'default' => ''), - 'Captcha' => Array('type' => 'string', 'default' => ''), 'RootPassword' => Array('type' => 'string', 'formatter' => 'kPasswordFormatter', 'encryption_method' => 'md5', 'verify_field' => 'VerifyRootPassword', 'skip_empty' => 1, 'default' => md5('') ), 'FullName' => Array ('type' => 'string', 'default' => ''), Index: branches/RC/themes/default2007/platform/login/register.tpl =================================================================== diff -u -N -r10517 -r10539 --- branches/RC/themes/default2007/platform/login/register.tpl (.../register.tpl) (revision 10517) +++ branches/RC/themes/default2007/platform/login/register.tpl (.../register.tpl) (revision 10539) @@ -65,18 +65,7 @@ - - "> - - - -
-
- " alt=""/>
- img/s.gif" width="1" height="5" alt=""/>
- " value="" tabindex="" style="width: 170px;"> - - +
Index: branches/RC/core/units/general/helpers/captcha_helper.php =================================================================== diff -u -N -r8929 -r10539 --- branches/RC/core/units/general/helpers/captcha_helper.php (.../captcha_helper.php) (revision 8929) +++ branches/RC/core/units/general/helpers/captcha_helper.php (.../captcha_helper.php) (revision 10539) @@ -109,4 +109,55 @@ return false; } + /** + * Generates captcha code for showing on form + * + * @param kEvent $event + */ + function prepareCode(&$event) + { + if ($this->Application->IsAdmin() || $this->Application->RecallVar($event->getPrefixSpecial() . '_captcha_code')) { + // when code found don't generate it 2nd time + return ; + } + + $this->Application->StoreVar($event->getPrefixSpecial() . '_captcha_code', $this->GenerateCaptchaCode()); + } + + /** + * Validates captcha code on form + * + * @param kEvent $event + * @param bool $check_request + * @return bool + */ + function validateCode(&$event, $check_request = true) + { + if ($this->Application->IsAdmin()) { + // no captcha codes in admin + return true; + } + + if ($check_request) { + // perform validation only when field is found on form + list ($id, $field_values) = each($this->Application->GetVar($event->getPrefixSpecial())); + if (!array_key_exists('Captcha', $field_values)) { + // when captcha code not submitted + return true; + } + } + + $object =& $event->getObject(); + /* @var $object kDBItem */ + + if ($object->GetDBField('Captcha') != $this->Application->RecallVar($event->getPrefixSpecial() . '_captcha_code')) { + $object->SetError('Captcha', 'captcha_error', 'lu_captcha_error'); + + $this->Application->StoreVar($event->getPrefixSpecial() . '_captcha_code', $this->GenerateCaptchaCode()); + return false; + } + + return true; + } + } \ No newline at end of file Index: branches/RC/core/units/users/users_event_handler.php =================================================================== diff -u -N -r10517 -r10539 --- branches/RC/core/units/users/users_event_handler.php (.../users_event_handler.php) (revision 10517) +++ branches/RC/core/units/users/users_event_handler.php (.../users_event_handler.php) (revision 10539) @@ -1291,27 +1291,6 @@ } /** - * Apply some special processing to - * object beeing recalled before using - * it in other events that call prepareObject - * - * @param Object $object - * @param kEvent $event - * @access protected - */ - function prepareObject(&$object, &$event) - { - parent::prepareObject($object, $event); - - if (!$this->Application->IsAdmin()) { - if ($this->Application->RecallVar('register_captcha_code')) return ; - $captcha_helper =& $this->Application->recallObject('CaptchaHelper'); - /* @var $captcha_helper kCaptchaHelper */ - $this->Application->StoreVar('register_captcha_code', $captcha_helper->GenerateCaptchaCode()); - } - } - - /** * Apply custom processing to item * * @param kEvent $event @@ -1328,14 +1307,13 @@ $object->SetDBField('Password_plain', $object->GetDirtyField('Password')); } - // Validate captcha image if it's requried - if ($this->Application->ConfigValue('RegistrationCaptcha') && $object->GetDBField('Captcha') != $this->Application->RecallVar('register_captcha_code')) { - $object->SetError('Captcha', 'captcha_error', 'lu_captcha_error'); + // validate here, because subscribing procedure should not validate captcha code + if ($this->Application->ConfigValue('RegistrationCaptcha')) { $captcha_helper =& $this->Application->recallObject('CaptchaHelper'); /* @var $captcha_helper kCaptchaHelper */ - $this->Application->StoreVar('register_captcha_code', $captcha_helper->GenerateCaptchaCode()); - } + $captcha_helper->validateCode($event, false); + } } } Index: branches/RC/core/units/captcha/captcha_config.php =================================================================== diff -u -N --- branches/RC/core/units/captcha/captcha_config.php (revision 0) +++ branches/RC/core/units/captcha/captcha_config.php (revision 10539) @@ -0,0 +1,8 @@ + 'captcha', +// 'ItemClass' => Array ('class' => 'kDBItem', 'file' => '', 'build_event' => 'OnItemBuild'), +// 'ListClass' => Array ('class' => 'kDBList', 'file' => '', 'build_event' => 'OnListBuild'), + 'EventHandlerClass' => Array('class' => 'CaptchaEventHandler', 'file' => 'captcha_eh.php', 'build_event' => 'OnBuild'), + ); \ No newline at end of file Index: branches/RC/core/units/captcha/captcha_eh.php =================================================================== diff -u -N --- branches/RC/core/units/captcha/captcha_eh.php (revision 0) +++ branches/RC/core/units/captcha/captcha_eh.php (revision 10539) @@ -0,0 +1,36 @@ +Application->recallObject('CaptchaHelper'); + /* @var $captcha_helper kCaptchaHelper */ + + $captcha_helper->validateCode($event->MasterEvent); + } + + /** + * [HOOK] Initializes captcha code processing routine + * + * @param kEvent $event + */ + function OnPrepareCaptcha(&$event) + { + $captcha_helper =& $this->Application->recallObject('CaptchaHelper'); + /* @var $captcha_helper kCaptchaHelper */ + + // generate captcha code + $captcha_helper->prepareCode($event->MasterEvent); + + // create field for captcha code storage + $virtual_fields = $this->Application->getUnitOption($event->MasterEvent->Prefix, 'VirtualFields'); + $virtual_fields['Captcha'] = Array ('type' => 'string', 'default' => ''); + $this->Application->setUnitOption($event->MasterEvent->Prefix, 'VirtualFields', $virtual_fields); + } + }