قرینه از
https://github.com/matomo-org/matomo.git
synced 2025-08-21 22:47:43 +00:00

* Add new setting for enabling inactive user notifications (#23393) * Migrate 'last seen' from options table to users table (#23388) * Create scheduled task to send inactive users security notification (#23403) * Simplify enrich user and remove surplus methods * Create a language helper to run code using given user's preferred language * Update UI test screenshots --------- Co-authored-by: Nathan Gavin <nathangavin987@gmail.com>
100 خطوط
4.1 KiB
PHP
100 خطوط
4.1 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Matomo - free/libre analytics platform
|
|
*
|
|
* @link https://matomo.org
|
|
* @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
|
*/
|
|
|
|
namespace Piwik\Plugins\UsersManager;
|
|
|
|
use Piwik\Piwik;
|
|
use Piwik\Plugins\UsersManager\Validators\AllowedEmailDomain;
|
|
use Piwik\Settings\Setting;
|
|
use Piwik\Settings\FieldConfig;
|
|
|
|
/**
|
|
* Defines Settings for UsersManager.
|
|
*/
|
|
class SystemSettings extends \Piwik\Settings\Plugin\SystemSettings
|
|
{
|
|
/** @var Setting */
|
|
public $allowedEmailDomains;
|
|
|
|
/** @var Setting */
|
|
public $enableInactiveUsersNotifications;
|
|
|
|
protected function init()
|
|
{
|
|
$this->allowedEmailDomains = $this->createAllowedEmailDomains();
|
|
$this->enableInactiveUsersNotifications = $this->createEnableInactiveUsersNotifications();
|
|
}
|
|
|
|
private function createEnableInactiveUsersNotifications(): Setting
|
|
{
|
|
return $this->makeSetting('enableInactiveUsersNotifications', $default = false, FieldConfig::TYPE_BOOL, function (FieldConfig $field) {
|
|
$field->title = Piwik::translate('UsersManager_SettingEnableInactiveUsersNotifications');
|
|
$field->description = Piwik::translate('UsersManager_SettingEnableInactiveUsersNotificationsHelp');
|
|
$field->uiControl = FieldConfig::UI_CONTROL_CHECKBOX;
|
|
});
|
|
}
|
|
|
|
private function createAllowedEmailDomains()
|
|
{
|
|
return $this->makeSetting('allowedEmailDomains', array(), FieldConfig::TYPE_ARRAY, function (FieldConfig $field) {
|
|
$field->title = Piwik::translate('UsersManager_SettingRestrictLoginEmailDomains');
|
|
$field->uiControl = FieldConfig::UI_CONTROL_FIELD_ARRAY;
|
|
$title = Piwik::translate('UsersManager_SettingFieldAllowedEmailDomain');
|
|
$arrayField = new FieldConfig\ArrayField($title, FieldConfig::UI_CONTROL_TEXT);
|
|
$field->uiControlAttributes['field'] = $arrayField->toArray();
|
|
$field->description = Piwik::translate('UsersManager_SettingRestrictLoginEmailDomainsHelp');
|
|
|
|
$allowedEmailDomains = new AllowedEmailDomain($this);
|
|
$domainsInUse = $allowedEmailDomains->getEmailDomainsInUse();
|
|
$field->inlineHelp .= '<br><strong>' . Piwik::translate('UsersManager_SettingRestrictLoginEmailDomainsHelpInUse') . '</strong>';
|
|
$field->inlineHelp .= '<br>' . implode('<br>', $domainsInUse);
|
|
|
|
$field->validate = function ($value) use ($field, $allowedEmailDomains) {
|
|
$value = call_user_func($field->transform, $value, $this);
|
|
|
|
if (empty($value)) {
|
|
return;
|
|
}
|
|
|
|
$domainsInUse = $allowedEmailDomains->getEmailDomainsInUse();
|
|
$notMatchingDomains = array_diff($domainsInUse, $value);
|
|
|
|
if (!empty($notMatchingDomains)) {
|
|
$notMatchingDomains = implode(', ', array_unique($notMatchingDomains));
|
|
$message = Piwik::translate('UsersManager_SettingRestrictLoginEmailDomainsErrorOtherDomainsInUse', $notMatchingDomains);
|
|
throw new \Exception($message);
|
|
}
|
|
};
|
|
$field->transform = function ($domains) {
|
|
if (empty($domains)) {
|
|
return array();
|
|
}
|
|
|
|
if (!is_array($domains)) {
|
|
$domains = [$domains];
|
|
}
|
|
|
|
$domains = array_map(function ($domain) {
|
|
$domain = trim($domain);
|
|
if (mb_strpos($domain, '@') !== false) {
|
|
// handle incorrect user input such as leading @ or entered email address
|
|
$allowedEmailDomains = new AllowedEmailDomain($this);
|
|
$domain = $allowedEmailDomains->getDomainFromEmail($domain);
|
|
}
|
|
return mb_strtolower($domain);
|
|
}, $domains);
|
|
$domains = array_filter($domains, 'strlen');
|
|
$domains = array_unique($domains);
|
|
$domains = array_values($domains);
|
|
return $domains;
|
|
};
|
|
});
|
|
}
|
|
}
|