Skip to content

Commit

Permalink
dynamic csrf in login form
Browse files Browse the repository at this point in the history
  • Loading branch information
Lampret, Alexander committed Apr 2, 2020
1 parent 6d77efe commit 3c0179a
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/ZfcUser/Form/Login.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,17 @@ public function __construct($name, AuthenticationOptionsInterface $options)
),
));

$this->add([
'type' => '\Zend\Form\Element\Csrf',
'name' => 'security',
'options' => [
'csrf_options' => [
'timeout' => $this->getAuthenticationOptions()->getLoginFormTimeout()
if ($this->getAuthenticationOptions()->getUseLoginFormCsrf()) {
$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',
Expand Down
15 changes: 15 additions & 0 deletions src/ZfcUser/Options/AuthenticationOptionsInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,21 @@ public function setUseLoginFormCaptcha($useRegistrationFormCaptcha);
*/
public function getUseLoginFormCaptcha();

/**
* set use a csrf in login form
*
* @param bool $useRegistrationFormCaptcha
* @return ModuleOptions
*/
public function setUseLoginFormCsrf($useLoginFormCsrf);

/**
* get use a csrf in login form
*
* @return bool
*/
public function getUseLoginFormCsrf();

/**
* set form CAPTCHA options
*
Expand Down
27 changes: 27 additions & 0 deletions src/ZfcUser/Options/ModuleOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ class ModuleOptions extends AbstractOptions implements
* @var bool
*/
protected $useLoginFormCaptcha = false;

/**
* @var bool
*/
protected $useLoginFormCsrf = true;

/**
* @var int
Expand Down Expand Up @@ -499,6 +504,28 @@ public function getUseLoginFormCaptcha()
{
return $this->useLoginFormCaptcha;
}

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

/**
* get use a csrf in login form
*
* @return bool
*/
public function getUseLoginFormCsrf()
{
return $this->useLoginFormCsrf;
}

/**
* set user entity class name
Expand Down

0 comments on commit 3c0179a

Please sign in to comment.