get module setting from service

This commit is contained in:
Daniel Seifert 2024-09-21 13:34:44 +02:00
bovenliggende 12d47d14f0
commit e509aa7eff
Getekend door: DanielS
GPG sleutel-ID: 6A513E13AEE66170
2 gewijzigde bestanden met toevoegingen van 45 en 11 verwijderingen

Bestand weergeven

@ -4,13 +4,20 @@ declare(strict_types=1);
namespace D3\Totp\Application\Controller\Admin;
use D3\Totp\Application\Model\Constants;
use D3\Totp\Application\Model\d3totp_conf;
use OxidEsales\Eshop\Core\Registry;
use OxidEsales\Eshop\Core\Session;
use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory;
use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\Bridge\ModuleConfigurationDaoBridgeInterface;
use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\DataObject\ModuleConfiguration;
use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\Exception\ModuleSettingNotFountException;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
class d3force_2fa extends d3user_totp
{
public function render()
public function render(): string
{
$this->addTplParam('force2FA', true);
@ -21,7 +28,7 @@ class d3force_2fa extends d3user_totp
}
protected function _authorize()
protected function authorize(): bool
{
$userID = $this->d3TotpGetSessionObject()->getVariable(d3totp_conf::OXID_ADMIN_AUTH);
@ -31,17 +38,27 @@ class d3force_2fa extends d3user_totp
/**
* @return Session
*/
private function d3TotpGetSessionObject()
private function d3TotpGetSessionObject(): Session
{
return Registry::getSession();
}
/**
* @return bool
* @throws ModuleSettingNotFountException
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
private function d3IsAdminForce2FA()
private function d3IsAdminForce2FA(): bool
{
return $this->isAdmin() &&
Registry::getConfig()->getConfigParam('D3_TOTP_ADMIN_FORCE_2FA') == true;
if (!$this->isAdmin()) {
return false;
}
$container = ContainerFactory::getInstance()->getContainer();
$moduleConfigurationBridge = $container->get(ModuleConfigurationDaoBridgeInterface::class);
/** @var ModuleConfiguration $moduleConfiguration */
$moduleConfiguration = $moduleConfigurationBridge->get(Constants::OXID_MODULE_ID);
return (bool) $moduleConfiguration->getModuleSetting('D3_TOTP_ADMIN_FORCE_2FA')->getValue();
}
}

Bestand weergeven

@ -15,6 +15,7 @@ declare(strict_types=1);
namespace D3\Totp\Modules\Core;
use D3\Totp\Application\Model\Constants;
use D3\Totp\Application\Model\d3totp;
use D3\Totp\Application\Model\d3totp_conf;
use Doctrine\DBAL\DBALException;
@ -22,6 +23,12 @@ use OxidEsales\Eshop\Core\Config;
use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException;
use OxidEsales\Eshop\Core\Registry;
use OxidEsales\Eshop\Core\Session;
use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory;
use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\Bridge\ModuleConfigurationDaoBridgeInterface;
use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\DataObject\ModuleConfiguration;
use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\Exception\ModuleSettingNotFountException;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
class d3_totp_utils extends d3_totp_utils_parent
{
@ -60,7 +67,7 @@ class d3_totp_utils extends d3_totp_utils_parent
/**
* @return Session
*/
public function d3TotpGetSessionObject()
public function d3TotpGetSessionObject(): Session
{
return Registry::getSession();
}
@ -68,7 +75,7 @@ class d3_totp_utils extends d3_totp_utils_parent
/**
* @return d3totp
*/
public function d3GetTotpObject()
public function d3GetTotpObject(): d3totp
{
return oxNew(d3totp::class);
}
@ -83,11 +90,21 @@ class d3_totp_utils extends d3_totp_utils_parent
/**
* @return bool
* @throws ModuleSettingNotFountException
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
protected function d3IsAdminForce2FA()
protected function d3IsAdminForce2FA(): bool
{
return $this->isAdmin() &&
$this->d3GetConfig()->getConfigParam('D3_TOTP_ADMIN_FORCE_2FA') === true;
if (!$this->isAdmin()) {
return false;
}
$container = ContainerFactory::getInstance()->getContainer();
$moduleConfigurationBridge = $container->get(ModuleConfigurationDaoBridgeInterface::class);
/** @var ModuleConfiguration $moduleConfiguration */
$moduleConfiguration = $moduleConfigurationBridge->get(Constants::OXID_MODULE_ID);
return (bool) $moduleConfiguration->getModuleSetting('D3_TOTP_ADMIN_FORCE_2FA')->getValue();
}
/**