Skip to content

Commit e455c68

Browse files
committed
MC-37886: 2FA fixes
1 parent ae070bf commit e455c68

File tree

2 files changed

+6
-36
lines changed

2 files changed

+6
-36
lines changed

TwoFactorAuth/Controller/Adminhtml/Tfa/Requestconfig.php

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919
use Magento\TwoFactorAuth\Api\UserConfigRequestManagerInterface;
2020
use Magento\TwoFactorAuth\Controller\Adminhtml\AbstractAction;
2121
use Magento\TwoFactorAuth\Model\UserConfig\HtmlAreaTokenVerifier;
22-
use Magento\TwoFactorAuth\Model\TfaSession;
23-
use Magento\Framework\App\ObjectManager;
24-
use Magento\TwoFactorAuth\Model\Exception\NotificationException;
2522

2623
/**
2724
* Request 2FA config from the user.
@@ -33,6 +30,8 @@ class Requestconfig extends AbstractAction implements HttpGetActionInterface, Ht
3330
*/
3431
public const ADMIN_RESOURCE = 'Magento_TwoFactorAuth::tfa';
3532

33+
private const TFA_EMAIL_SENT = 'tfa_email_sent';
34+
3635
/**
3736
* @var UserConfigRequestManagerInterface
3837
*/
@@ -53,33 +52,25 @@ class Requestconfig extends AbstractAction implements HttpGetActionInterface, Ht
5352
*/
5453
private $session;
5554

56-
/**
57-
* @var TfaSession
58-
*/
59-
private $tfaSession;
60-
6155
/**
6256
* @param Context $context
6357
* @param UserConfigRequestManagerInterface $configRequestManager
6458
* @param HtmlAreaTokenVerifier $tokenVerifier
6559
* @param TfaInterface $tfa
6660
* @param Session $session
67-
* @param TfaSession $tfaSession
6861
*/
6962
public function __construct(
7063
Context $context,
7164
UserConfigRequestManagerInterface $configRequestManager,
7265
HtmlAreaTokenVerifier $tokenVerifier,
7366
TfaInterface $tfa,
74-
Session $session,
75-
TfaSession $tfaSession
67+
Session $session
7668
) {
7769
parent::__construct($context);
7870
$this->configRequestManager = $configRequestManager;
7971
$this->tokenVerifier = $tokenVerifier;
8072
$this->tfa = $tfa;
8173
$this->session = $session;
82-
$this->tfaSession = $tfaSession ?? ObjectManager::getInstance()->get(TfaSession::class);
8374
}
8475

8576
/**
@@ -100,11 +91,10 @@ public function execute()
10091
}
10192

10293
try {
103-
if ($this->tfaSession->isTfaEmailSent()) {
104-
throw new NotificationException();
94+
if (!$this->session->getData(self::TFA_EMAIL_SENT)) {
95+
$this->configRequestManager->sendConfigRequestTo($user);
96+
$this->session->setData(self::TFA_EMAIL_SENT, true);
10597
}
106-
$this->configRequestManager->sendConfigRequestTo($user);
107-
$this->tfaSession->setTfaEmailSentFlag();
10898
} catch (AuthorizationException $exception) {
10999
$this->messageManager->addErrorMessage(
110100
'Please ask an administrator with sufficient access to configure 2FA first'

TwoFactorAuth/Model/TfaSession.php

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ class TfaSession extends SessionManager implements TfaSessionInterface
1919
{
2020
const SKIPPED_PROVIDERS_KEY = 'tfa_skipped_config';
2121

22-
private const TFA_EMAIL_SENT = 'tfa_email_sent';
23-
2422
/**
2523
* @inheritDoc
2624
*/
@@ -54,22 +52,4 @@ public function setSkippedProviderConfig(array $config): void
5452
{
5553
$this->storage->setData(static::SKIPPED_PROVIDERS_KEY, $config);
5654
}
57-
58-
/**
59-
* Get flag that tfa configuration email was sent
60-
*
61-
* @return bool
62-
*/
63-
public function isTfaEmailSent(): bool
64-
{
65-
return (bool) $this->storage->getData(self::TFA_EMAIL_SENT);
66-
}
67-
68-
/**
69-
* Set flag that tfa configuration email was sent
70-
*/
71-
public function setTfaEmailSentFlag(): void
72-
{
73-
$this->storage->setData(self::TFA_EMAIL_SENT, true);
74-
}
7555
}

0 commit comments

Comments
 (0)