3 use wcf\system\captcha\CaptchaHandler
;
4 use wcf\system\exception\SystemException
;
8 * Abstract implementation of a form using captcha.
10 * @author Matthias Schmidt
11 * @copyright 2001-2016 WoltLab GmbH
12 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
13 * @package com.woltlab.wcf
15 * @category Community Framework
17 abstract class AbstractCaptchaForm
extends AbstractForm
{
19 * captcha object type object
20 * @var \wcf\data\object\type\ObjectType
22 public $captchaObjectType = null;
25 * name of the captcha object type; if empty, captcha is disabled
28 public $captchaObjectTypeName = CAPTCHA_TYPE
;
31 * true if captcha is used
34 public $useCaptcha = true;
37 * true to force captcha usage
40 public $forceCaptcha = false;
45 public function assignVariables() {
46 parent
::assignVariables();
48 WCF
::getTPL()->assign([
49 'captchaObjectType' => $this->captchaObjectType
,
50 'useCaptcha' => $this->useCaptcha
57 public function readData() {
58 if ((!WCF
::getUser()->userID ||
$this->forceCaptcha
) && $this->useCaptcha
&& $this->captchaObjectTypeName
) {
59 $this->captchaObjectType
= CaptchaHandler
::getInstance()->getObjectTypeByName($this->captchaObjectTypeName
);
60 if ($this->captchaObjectType
=== null) {
61 throw new SystemException("Unknown captcha object type with name '".$this->captchaObjectTypeName
."'");
64 if (!$this->captchaObjectType
->getProcessor()->isAvailable()) {
65 $this->captchaObjectType
= null;
75 public function readFormParameters() {
76 parent
::readFormParameters();
78 if ($this->captchaObjectType
) {
79 $this->captchaObjectType
->getProcessor()->readFormParameters();
86 public function save() {
89 if ($this->captchaObjectType
) {
90 $this->captchaObjectType
->getProcessor()->reset();
97 public function validate() {
100 $this->validateCaptcha();
104 * Validates the captcha.
106 protected function validateCaptcha() {
107 if ($this->captchaObjectType
) {
108 $this->captchaObjectType
->getProcessor()->validate();