mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-09-26 11:19:14 +02:00
add constructor for password policy objekt
This commit is contained in:
parent
50b74207fc
commit
08e24ad860
@ -4,6 +4,7 @@
|
||||
namespace Icinga\Forms\Account;
|
||||
|
||||
use Icinga\Application\Config;
|
||||
use Icinga\Application\Hook\PasswordPolicyHook;
|
||||
use Icinga\Authentication\PasswordValidator;
|
||||
use Icinga\Authentication\User\DbUserBackend;
|
||||
use Icinga\Data\Filter\Filter;
|
||||
@ -23,6 +24,23 @@ class ChangePasswordForm extends Form
|
||||
*/
|
||||
protected $backend;
|
||||
|
||||
/**
|
||||
* The password policy object
|
||||
*
|
||||
* @var PasswordPolicyHook|null
|
||||
*/
|
||||
protected ?PasswordPolicyHook $passwordPolicyObject;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param PasswordPolicyHook|null $passwordPolicyObject
|
||||
*/
|
||||
public function __construct($passwordPolicyObject = null)
|
||||
{
|
||||
$this->passwordPolicyObject = $passwordPolicyObject;
|
||||
parent::__construct();
|
||||
}
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@ -33,47 +51,55 @@ class ChangePasswordForm extends Form
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* @throws \Zend_Validate_Exception
|
||||
*/
|
||||
public function createElements(array $formData)
|
||||
{
|
||||
$passwordPolicy = Config::app()->get('global', 'password_policy');
|
||||
if (isset($passwordPolicy) && class_exists($passwordPolicy)) {
|
||||
$passwordPolicyObject = new $passwordPolicy();
|
||||
$this->addDescription($passwordPolicyObject->displayPasswordPolicy());
|
||||
if ($this->passwordPolicyObject === null) {
|
||||
$passwordPolicy = Config::app()->get(
|
||||
'global',
|
||||
'password_policy'
|
||||
);
|
||||
if (isset($passwordPolicy) && class_exists($passwordPolicy)) {
|
||||
$this->passwordPolicyObject = new $passwordPolicy();
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->passwordPolicyObject) {
|
||||
$this->addDescription(
|
||||
$this->passwordPolicyObject->displayPasswordPolicy()
|
||||
);
|
||||
}
|
||||
|
||||
$this->addElement(
|
||||
'password',
|
||||
'old_password',
|
||||
array(
|
||||
'label' => $this->translate('Old Password'),
|
||||
'required' => true
|
||||
'label' => $this->translate('Old Password'),
|
||||
'required' => true
|
||||
)
|
||||
);
|
||||
$this->addElement(
|
||||
'password',
|
||||
'new_password',
|
||||
array(
|
||||
'label' => $this->translate('New Password'),
|
||||
'required' => true,
|
||||
'validators' => array(new PasswordValidator())
|
||||
'label' => $this->translate('New Password'),
|
||||
'required' => true,
|
||||
'validators' => [new PasswordValidator()]
|
||||
)
|
||||
);
|
||||
$this->addElement(
|
||||
'password',
|
||||
'new_password_confirmation',
|
||||
array(
|
||||
'label' => $this->translate('Confirm New Password'),
|
||||
'required' => true,
|
||||
'validators' => array(
|
||||
'label' => $this->translate('Confirm New Password'),
|
||||
'required' => true,
|
||||
'validators' => array(
|
||||
array('identical', false, array('new_password'))
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@ -94,13 +120,13 @@ class ChangePasswordForm extends Form
|
||||
public function isValid($formData)
|
||||
{
|
||||
$valid = parent::isValid($formData);
|
||||
if (!$valid) {
|
||||
if (! $valid) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$oldPasswordEl = $this->getElement('old_password');
|
||||
|
||||
if (!$this->backend->authenticate($this->Auth()->getUser(), $oldPasswordEl->getValue())) {
|
||||
if (! $this->backend->authenticate($this->Auth()->getUser(), $oldPasswordEl->getValue())) {
|
||||
$oldPasswordEl->addError($this->translate('Old password is invalid'));
|
||||
$this->markAsError();
|
||||
return false;
|
||||
@ -122,7 +148,7 @@ class ChangePasswordForm extends Form
|
||||
/**
|
||||
* Set the user backend
|
||||
*
|
||||
* @param DbUserBackend $backend
|
||||
* @param DbUserBackend $backend
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user