-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSystemSettings.php
87 lines (72 loc) · 3.83 KB
/
SystemSettings.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
declare(strict_types=1);
namespace Piwik\Plugins\PasswordPolicyEnforcer;
use Piwik\Piwik;
use Piwik\Plugins\UsersManager\UsersManager;
use Piwik\Settings\FieldConfig;
use Piwik\Settings\Setting;
use Piwik\Validators\NumberRange;
/** @psalm-suppress UndefinedClass **/
class SystemSettings extends \Piwik\Settings\Plugin\SystemSettings
{
/** @var Setting */
public $minLength;
/** @var Setting */
public $isOneUppercaseLetterRequired;
/** @var Setting */
public $isOneLowercaseLetterRequired;
/** @var Setting */
public $isOneNumberRequired;
/** @var Setting */
public $isOneSpecialCharacterRequired;
protected function init()
{
$this->title = Piwik::translate('PasswordPolicyEnforcer_PasswordPolicyConfiguration');
$this->minLength = $this->createMinLengthSetting();
$this->isOneUppercaseLetterRequired = $this->createRequireOneUppercaseLetterSetting();
$this->isOneLowercaseLetterRequired = $this->createRequireOneLowercaseLetterSetting();
$this->isOneNumberRequired = $this->createRequireOneNumberSetting();
$this->isOneSpecialCharacterRequired = $this->createRequireOneSpecialCharacterSetting();
}
private function createMinLengthSetting()
{
return $this->makeSetting('minLength', UsersManager::PASSWORD_MIN_LENGTH, FieldConfig::TYPE_INT, function (FieldConfig $field) {
$field->title = Piwik::translate('PasswordPolicyEnforcer_PasswordPolicyMinLengthSetting');
$field->uiControl = FieldConfig::UI_CONTROL_TEXT;
$field->description = Piwik::translate('PasswordPolicyEnforcer_PasswordPolicyMinLengthSettingDescription', [UsersManager::PASSWORD_MIN_LENGTH]);
$field->validators[] = new NumberRange(UsersManager::PASSWORD_MIN_LENGTH, UsersManager::PASSWORD_MAX_LENGTH);
});
}
private function createRequireOneUppercaseLetterSetting()
{
return $this->makeSetting('requireOneUppercaseLetter', false, FieldConfig::TYPE_BOOL, function (FieldConfig $field) {
$field->title = Piwik::translate('PasswordPolicyEnforcer_PasswordPolicyOneUppercaseLetterSetting');
$field->uiControl = FieldConfig::UI_CONTROL_CHECKBOX;
$field->description = Piwik::translate('PasswordPolicyEnforcer_PasswordPolicyOneUppercaseLetterSettingDescription');
});
}
private function createRequireOneLowercaseLetterSetting()
{
return $this->makeSetting('requireOneLowercaseLetter', false, FieldConfig::TYPE_BOOL, function (FieldConfig $field) {
$field->title = Piwik::translate('PasswordPolicyEnforcer_PasswordPolicyOneLowercaseLetterSetting');
$field->uiControl = FieldConfig::UI_CONTROL_CHECKBOX;
$field->description = Piwik::translate('PasswordPolicyEnforcer_PasswordPolicyOneLowercaseLetterSettingDescription');
});
}
private function createRequireOneNumberSetting()
{
return $this->makeSetting('requireOneNumber', false, FieldConfig::TYPE_BOOL, function (FieldConfig $field) {
$field->title = Piwik::translate('PasswordPolicyEnforcer_PasswordPolicyOneNumberSetting');
$field->uiControl = FieldConfig::UI_CONTROL_CHECKBOX;
$field->description = Piwik::translate('PasswordPolicyEnforcer_PasswordPolicyOneNumberSettingDescription');
});
}
private function createRequireOneSpecialCharacterSetting()
{
return $this->makeSetting('requireOneSpecialCharacter', false, FieldConfig::TYPE_BOOL, function (FieldConfig $field) {
$field->title = Piwik::translate('PasswordPolicyEnforcer_PasswordPolicyOneSpecialCharacterSetting');
$field->uiControl = FieldConfig::UI_CONTROL_CHECKBOX;
$field->description = Piwik::translate('PasswordPolicyEnforcer_PasswordPolicyOneSpecialCharacterSettingDescription');
});
}
}