123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245 |
- <?php
- /**
- * MageSpecialist
- *
- * NOTICE OF LICENSE
- *
- * This source file is subject to the Open Software License (OSL 3.0)
- * that is bundled with this package in the file LICENSE.txt.
- * It is also available through the world-wide-web at this URL:
- * http://opensource.org/licenses/osl-3.0.php
- * If you did not receive a copy of the license and are unable to
- * obtain it through the world-wide-web, please send an email
- * to info@magespecialist.it so we can send you a copy immediately.
- *
- * @category MSP
- * @package MSP_TwoFactorAuth
- * @copyright Copyright (c) 2017 Skeeller srl (http://www.magespecialist.it)
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
- */
- /**
- * MageSpecialist
- *
- * NOTICE OF LICENSE
- *
- * This source file is subject to the Open Software License (OSL 3.0)
- * that is bundled with this package in the file LICENSE.txt.
- * It is also available through the world-wide-web at this URL:
- * http://opensource.org/licenses/osl-3.0.php
- * If you did not receive a copy of the license and are unable to
- * obtain it through the world-wide-web, please send an email
- * to info@magespecialist.it so we can send you a copy immediately.
- *
- * @category MSP
- * @package MSP_NoSpam
- * @copyright Copyright (c) 2017 Skeeller srl (http://www.magespecialist.it)
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
- */
- namespace MSP\TwoFactorAuth\Model;
- use MSP\TwoFactorAuth\Api\ProviderInterface;
- use MSP\TwoFactorAuth\Api\UserConfigManagerInterface;
- use MSP\TwoFactorAuth\Api\EngineInterface;
- class Provider implements ProviderInterface
- {
- /**
- * @var EngineInterface
- */
- private $engine;
- /**
- * @var string
- */
- private $code;
- /**
- * @var string
- */
- private $name;
- /**
- * @var UserConfigManagerInterface
- */
- private $userConfigManager;
- /**
- * @var string
- */
- private $configureAction;
- /**
- * @var string
- */
- private $authAction;
- /**
- * @var string[]
- */
- private $extraActions;
- /**
- * @var bool
- */
- private $canReset;
- /**
- * @var string
- */
- private $icon;
- public function __construct(
- EngineInterface $engine,
- UserConfigManagerInterface $userConfigManager,
- $code,
- $name,
- $icon,
- $configureAction,
- $authAction,
- $extraActions = [],
- $canReset = true
- ) {
- $this->engine = $engine;
- $this->userConfigManager = $userConfigManager;
- $this->code = $code;
- $this->name = $name;
- $this->configureAction = $configureAction;
- $this->authAction = $authAction;
- $this->extraActions = $extraActions;
- $this->canReset = $canReset;
- $this->icon = $icon;
- }
- /**
- * Return true if this provider has been enabled by admin
- * @return boolean
- */
- public function isEnabled()
- {
- return $this->getEngine()->isEnabled();
- }
- /**
- * Get provider engine
- * @return EngineInterface
- */
- public function getEngine()
- {
- return $this->engine;
- }
- /**
- * Get provider code
- * @return string
- */
- public function getCode()
- {
- return $this->code;
- }
- /**
- * Get provider name
- * @return string
- */
- public function getName()
- {
- return $this->name;
- }
- /**
- * Get provider icon
- * @return string
- */
- public function getIcon()
- {
- return $this->icon;
- }
- /**
- * Return true if this provider configuration can be reset
- * @return boolean
- */
- public function isResetAllowed()
- {
- return $this->canReset;
- }
- /**
- * Return true if this provider allows trusted devices
- * @return boolean
- */
- public function isTrustedDevicesAllowed()
- {
- return $this->engine->isTrustedDevicesAllowed();
- }
- /**
- * @inheritdoc
- */
- public function resetConfiguration($userId)
- {
- $this->userConfigManager->setProviderConfig($userId, $this->getCode(), null);
- return $this;
- }
- /**
- * @inheritdoc
- */
- public function isConfigured($userId)
- {
- return $this->getConfiguration($userId) !== null;
- }
- /**
- * @inheritdoc
- */
- public function getConfiguration($userId)
- {
- return $this->userConfigManager->getProviderConfig($userId, $this->getCode());
- }
- /**
- * @inheritdoc
- */
- public function isActive($userId)
- {
- return $this->userConfigManager->isProviderConfigurationActive($userId, $this->getCode());
- }
- /**
- * @inheritdoc
- */
- public function activate($userId)
- {
- $this->userConfigManager->activateProviderConfiguration($userId, $this->getCode());
- return $this;
- }
- /**
- * Get configure action
- * @return string
- */
- public function getConfigureAction()
- {
- return $this->configureAction;
- }
- /**
- * Get auth action
- * @return string
- */
- public function getAuthAction()
- {
- return $this->authAction;
- }
- /**
- * Get allowed extra actions
- * @return string[]
- */
- public function getExtraActions()
- {
- return $this->extraActions;
- }
- }
|