Skip to content

Commit

Permalink
Merge 163ae61 into 935b971
Browse files Browse the repository at this point in the history
  • Loading branch information
lampi87 committed Mar 5, 2018
2 parents 935b971 + 163ae61 commit 5a74ecc
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 8 deletions.
28 changes: 20 additions & 8 deletions src/ZfcUser/Form/Login.php
Expand Up @@ -47,14 +47,26 @@ public function __construct($name, AuthenticationOptionsInterface $options)
),
));

// @todo: Fix this
// 1) getValidator() is a protected method
// 2) i don't believe the login form is actually being validated by the login action
// (but keep in mind we don't want to show invalid username vs invalid password or
// anything like that, it should just say "login failed" without any additional info)
//$csrf = new Element\Csrf('csrf');
//$csrf->getValidator()->setTimeout($options->getLoginFormTimeout());
//$this->add($csrf);
$this->add([
'type' => '\Zend\Form\Element\Csrf',
'name' => 'security',
'options' => [
'csrf_options' => [
'timeout' => $this->getAuthenticationOptions()->getLoginFormTimeout()
]
]
]);

if ($this->getAuthenticationOptions()->getUseLoginFormCaptcha()) {
$this->add(array(
'name' => 'captcha',
'type' => 'Zend\Form\Element\Captcha',
'options' => array(
'label' => 'Human check',
'captcha' => $this->getAuthenticationOptions()->getFormCaptchaOptions(),
),
));
}

$submitElement = new Element\Button('submit');
$submitElement
Expand Down
30 changes: 30 additions & 0 deletions src/ZfcUser/Options/AuthenticationOptionsInterface.php
Expand Up @@ -33,4 +33,34 @@ public function setAuthIdentityFields($authIdentityFields);
* @return array
*/
public function getAuthIdentityFields();

/**
* set use a captcha in registration form
*
* @param bool $useRegistrationFormCaptcha
* @return ModuleOptions
*/
public function setUseLoginFormCaptcha($useRegistrationFormCaptcha);

/**
* get use a captcha in registration form
*
* @return bool
*/
public function getUseLoginFormCaptcha();

/**
* set form CAPTCHA options
*
* @param array $formCaptchaOptions
* @return ModuleOptions
*/
public function setFormCaptchaOptions($formCaptchaOptions);

/**
* get form CAPTCHA options
*
* @return array
*/
public function getFormCaptchaOptions();
}
27 changes: 27 additions & 0 deletions src/ZfcUser/Options/ModuleOptions.php
Expand Up @@ -97,6 +97,11 @@ class ModuleOptions extends AbstractOptions implements
* @var bool
*/
protected $useRegistrationFormCaptcha = false;

/**
* @var bool
*/
protected $useLoginFormCaptcha = false;

/**
* @var int
Expand Down Expand Up @@ -472,6 +477,28 @@ public function getUseRegistrationFormCaptcha()
{
return $this->useRegistrationFormCaptcha;
}

/**
* set use a captcha in login form
*
* @param bool $useRegistrationFormCaptcha
* @return ModuleOptions
*/
public function setUseLoginFormCaptcha($useLoginFormCaptcha)
{
$this->useLoginFormCaptcha = $useLoginFormCaptcha;
return $this;
}

/**
* get use a captcha in login form
*
* @return bool
*/
public function getUseLoginFormCaptcha()
{
return $this->useLoginFormCaptcha;
}

/**
* set user entity class name
Expand Down

0 comments on commit 5a74ecc

Please sign in to comment.