Skip to content

Commit

Permalink
Merge branch 'cs-refactoring'
Browse files Browse the repository at this point in the history
  • Loading branch information
phoenix128 committed Oct 19, 2017
2 parents 32a625b + 4a737f9 commit 4ed7940
Show file tree
Hide file tree
Showing 88 changed files with 1,692 additions and 1,123 deletions.
2 changes: 1 addition & 1 deletion Api/TfaInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ interface TfaInterface
* Return true if 2FA is enabled
* @return boolean
*/
public function getIsEnabled();
public function isEnabled();

/**
* Get provider by code
Expand Down
2 changes: 1 addition & 1 deletion Api/TfaSessionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ public function grantAccess();
* Return true if 2FA session has been passed
* @return boolean
*/
public function getIsGranted();
public function isGranted();
}
2 changes: 1 addition & 1 deletion Api/TrustedManagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function revokeTrustedDevice($tokenId);

/**
* Trust a device
* @param $providerCode
* @param string $providerCode
* @param RequestInterface $request
*/
public function handleTrustDeviceRequest($providerCode, RequestInterface $request);
Expand Down
2 changes: 1 addition & 1 deletion Api/UserConfigManagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function activateProviderConfiguration(UserInterface $user, $providerCode
* @param $providerCode
* @return boolean
*/
public function getProviderConfigurationIsActive(UserInterface $user, $providerCode);
public function isProviderConfigurationActive(UserInterface $user, $providerCode);

/**
* Set default provider
Expand Down
30 changes: 16 additions & 14 deletions Block/ChangeProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,13 @@

use Magento\Backend\Block\Template;
use Magento\Backend\Model\Auth\Session;
use Magento\Framework\Registry;
use Magento\User\Api\Data\UserInterface;
use Magento\Framework\Exception\LocalizedException;
use Magento\User\Model\User;
use MSP\TwoFactorAuth\Api\TfaInterface;
use MSP\TwoFactorAuth\Model\ProviderInterface;

class ChangeProvider extends Template
{
/**
* @var Registry
*/
private $registry;

/**
* @var TfaInterface
*/
Expand All @@ -45,15 +39,15 @@ class ChangeProvider extends Template
*/
private $session;

private $providerCode = null;

public function __construct(
Template\Context $context,
Registry $registry,
Session $session,
TfaInterface $tfa,
array $data = []
) {
parent::__construct($context, $data);
$this->registry = $registry;
$this->tfa = $tfa;
$this->session = $session;
}
Expand All @@ -62,28 +56,36 @@ public function __construct(
* Get user
* @return User|null
*/
protected function getUser()
private function getUser()
{
return $this->session->getUser();
}

/**
* Get current 2FA provider if defined
* @return string|null
* @return null|string
* @throws LocalizedException
*/
public function getCurrentProviderCode()
{
return $this->registry->registry('msp_tfa_current_provider');
if ($this->providerCode === null) {
$this->providerCode = $this->getData('provider');
if (!$this->providerCode) {
throw new LocalizedException(__('A provider must be defined for this block'));
}
}

return $this->providerCode;
}

/**
* Return true if current provider is active
* @return bool
*/
public function getCurrentProviderIsActive()
public function isCurrentProviderActive()
{
$currentProvider = $this->tfa->getProvider($this->getCurrentProviderCode());
return $currentProvider->getIsActive($this->getUser());
return $currentProvider->isActive($this->getUser());
}

/**
Expand Down
15 changes: 0 additions & 15 deletions Block/Provider/Authy/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,9 @@
namespace MSP\TwoFactorAuth\Block\Provider\Authy;

use Magento\Backend\Block\Template;
use MSP\TwoFactorAuth\Api\TfaInterface;

class Auth extends Template
{
/**
* @var TfaInterface
*/
private $tfa;

public function __construct(
Template\Context $context,
TfaInterface $tfa,
array $data = []
) {
parent::__construct($context, $data);
$this->tfa = $tfa;
}

public function getPostUrl()
{
return $this->getUrl('*/*/authpost');
Expand Down
8 changes: 0 additions & 8 deletions Block/Provider/Duo/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

use Magento\Backend\Block\Template;
use Magento\Backend\Model\Auth\Session;
use MSP\TwoFactorAuth\Api\TfaInterface;
use MSP\TwoFactorAuth\Model\Provider\Engine\DuoSecurity;

class Auth extends Template
Expand All @@ -32,26 +31,19 @@ class Auth extends Template
*/
private $duoSecurity;

/**
* @var TfaInterface
*/
private $tfa;

/**
* @var Session
*/
private $session;

public function __construct(
Template\Context $context,
TfaInterface $tfa,
Session $session,
DuoSecurity $duoSecurity,
array $data = []
) {
parent::__construct($context, $data);
$this->duoSecurity = $duoSecurity;
$this->tfa = $tfa;
$this->session = $session;
}

Expand Down
15 changes: 0 additions & 15 deletions Block/Provider/Google/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,9 @@
namespace MSP\TwoFactorAuth\Block\Provider\Google;

use Magento\Backend\Block\Template;
use MSP\TwoFactorAuth\Api\TfaInterface;

class Auth extends Template
{
/**
* @var TfaInterface
*/
private $tfa;

public function __construct(
Template\Context $context,
TfaInterface $tfa,
array $data = []
) {
parent::__construct($context, $data);
$this->tfa = $tfa;
}

public function getPostUrl()
{
return $this->getUrl('*/*/authpost');
Expand Down
8 changes: 0 additions & 8 deletions Block/Provider/U2fKey/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,10 @@
use Magento\Backend\Block\Template;
use Magento\Backend\Model\Auth\Session;
use Magento\Framework\Json\EncoderInterface;
use MSP\TwoFactorAuth\Api\TfaInterface;
use MSP\TwoFactorAuth\Model\Provider\Engine\U2fKey;

class Auth extends Template
{
/**
* @var TfaInterface
*/
private $tfa;

/**
* @var U2fKey
*/
Expand All @@ -50,14 +44,12 @@ class Auth extends Template

public function __construct(
Template\Context $context,
TfaInterface $tfa,
Session $session,
EncoderInterface $encoder,
U2fKey $u2fKey,
array $data = []
) {
parent::__construct($context, $data);
$this->tfa = $tfa;
$this->u2fKey = $u2fKey;
$this->encoder = $encoder;
$this->session = $session;
Expand Down
6 changes: 3 additions & 3 deletions Block/Provider/U2fKey/Configure.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public function __construct(
EncoderInterface $encoder,
U2fKey $u2fKey,
array $data = []
)
{
) {

parent::__construct($context, $data);
$this->u2fKey = $u2fKey;
$this->encoder = $encoder;
Expand Down Expand Up @@ -72,4 +72,4 @@ public function getConfigurePostUrl()
{
return $this->getUrl('*/*/configurepost');
}
}
}
35 changes: 14 additions & 21 deletions Block/TrustDevice.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,11 @@

use Magento\Backend\Block\Template;
use Magento\Backend\Model\Auth\Session;
use Magento\Framework\Registry;
use Magento\User\Model\User;
use Magento\Framework\Exception\LocalizedException;
use MSP\TwoFactorAuth\Api\TfaInterface;

class TrustDevice extends Template
{
/**
* @var Registry
*/
private $registry;

/**
* @var TfaInterface
*/
Expand All @@ -43,35 +37,34 @@ class TrustDevice extends Template
*/
private $session;

private $providerCode = null;

public function __construct(
Template\Context $context,
Registry $registry,
Session $session,
TfaInterface $tfa,
array $data = []
) {
parent::__construct($context, $data);
$this->registry = $registry;
$this->tfa = $tfa;
$this->session = $session;
}

/**
* Get user
* @return User|null
*/
protected function getUser()
{
return $this->session->getUser();
}

/**
* Get current 2FA provider if defined
* @return string|null
* @return null|string
* @throws LocalizedException
*/
public function getCurrentProviderCode()
{
return $this->registry->registry('msp_tfa_current_provider');
if ($this->providerCode === null) {
$this->providerCode = $this->getData('provider');
if (!$this->providerCode) {
throw new LocalizedException(__('A provider must be defined for this block'));
}
}

return $this->providerCode;
}

/**
Expand All @@ -81,6 +74,6 @@ public function getCurrentProviderCode()
public function canShowTrustDevice()
{
$provider = $this->tfa->getProvider($this->getCurrentProviderCode());
return $provider->getAllowTrustedDevices();
return $provider->isTrustedDevicesAllowed();
}
}
Loading

0 comments on commit 4ed7940

Please sign in to comment.