Skip to content

Commit 83a5728

Browse files
Rizwan KhanRizwan Khan
authored andcommitted
AC-9797: 2FA functionality enhancement
1 parent 744a532 commit 83a5728

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

TwoFactorAuth/Controller/Adminhtml/Authy/Authpost.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Magento\User\Model\User;
2222
use Magento\Framework\App\Config\ScopeConfigInterface;
2323
use Magento\User\Model\ResourceModel\User as UserResource;
24+
use Magento\Framework\App\ObjectManager;
2425

2526
/**
2627
* @SuppressWarnings(PHPMD.CamelCaseMethodName)
@@ -80,7 +81,7 @@ class Authpost extends AbstractAction implements HttpPostActionInterface
8081
/**
8182
* @var UserResource
8283
*/
83-
protected $userResource;
84+
private $userResource;
8485

8586
/**
8687
* @param Action\Context $context
@@ -91,8 +92,8 @@ class Authpost extends AbstractAction implements HttpPostActionInterface
9192
* @param TfaInterface $tfa
9293
* @param AlertInterface $alert
9394
* @param DataObjectFactory $dataObjectFactory
94-
* @param UserResource $userResource
95-
* @param ScopeConfigInterface $scopeConfig
95+
* @param UserResource|null $userResource
96+
* @param ScopeConfigInterface|null $scopeConfig
9697
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
9798
*/
9899
public function __construct(
@@ -104,8 +105,8 @@ public function __construct(
104105
TfaInterface $tfa,
105106
AlertInterface $alert,
106107
DataObjectFactory $dataObjectFactory,
107-
UserResource $userResource,
108-
ScopeConfigInterface $scopeConfig
108+
?UserResource $userResource = null,
109+
?ScopeConfigInterface $scopeConfig = null
109110
) {
110111
parent::__construct($context);
111112
$this->tfa = $tfa;
@@ -115,8 +116,8 @@ public function __construct(
115116
$this->authy = $authy;
116117
$this->dataObjectFactory = $dataObjectFactory;
117118
$this->alert = $alert;
118-
$this->userResource = $userResource;
119-
$this->scopeConfig = $scopeConfig;
119+
$this->scopeConfig = $scopeConfig ?? ObjectManager::getInstance()->get(ScopeConfigInterface::class);
120+
$this->userResource = $userResource ?? ObjectManager::getInstance()->get(UserResource::class);
120121
}
121122

122123
/**
@@ -140,7 +141,7 @@ public function execute()
140141
try {
141142
if (!$this->allowApiRetries()) { //locked the user
142143
$lockThreshold = $this->scopeConfig->getValue(self::XML_PATH_2FA_LOCK_EXPIRE);
143-
if ($this->userResource->lock($user->getId(), 0, $lockThreshold)) {
144+
if ($this->userResource->lock((int)$user->getId(), 0, $lockThreshold)) {
144145
$result->setData(['success' => false, 'message' => "Your account is temporarily disabled."]);
145146
return $result;
146147
}

TwoFactorAuth/Controller/Adminhtml/Google/Authpost.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Magento\User\Model\User;
2222
use Magento\Framework\App\Config\ScopeConfigInterface;
2323
use Magento\User\Model\ResourceModel\User as UserResource;
24+
use Magento\Framework\App\ObjectManager;
2425

2526
/**
2627
* Google authenticator post controller
@@ -92,8 +93,8 @@ class Authpost extends AbstractAction implements HttpPostActionInterface
9293
* @param TfaInterface $tfa
9394
* @param AlertInterface $alert
9495
* @param DataObjectFactory $dataObjectFactory
95-
* @param UserResource $userResource
96-
* @param ScopeConfigInterface $scopeConfig
96+
* @param UserResource|null $userResource
97+
* @param ScopeConfigInterface|null $scopeConfig
9798
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
9899
*/
99100
public function __construct(
@@ -105,8 +106,8 @@ public function __construct(
105106
TfaInterface $tfa,
106107
AlertInterface $alert,
107108
DataObjectFactory $dataObjectFactory,
108-
UserResource $userResource,
109-
ScopeConfigInterface $scopeConfig
109+
?UserResource $userResource = null,
110+
?ScopeConfigInterface $scopeConfig = null
110111
) {
111112
parent::__construct($context);
112113
$this->tfa = $tfa;
@@ -116,8 +117,8 @@ public function __construct(
116117
$this->tfaSession = $tfaSession;
117118
$this->dataObjectFactory = $dataObjectFactory;
118119
$this->alert = $alert;
119-
$this->userResource = $userResource;
120-
$this->scopeConfig = $scopeConfig;
120+
$this->scopeConfig = $scopeConfig ?? ObjectManager::getInstance()->get(ScopeConfigInterface::class);
121+
$this->userResource = $userResource ?? ObjectManager::getInstance()->get(UserResource::class);
121122
}
122123

123124
/**
@@ -134,7 +135,7 @@ public function execute()
134135

135136
if (!$this->allowApiRetries()) { //locked the user
136137
$lockThreshold = $this->scopeConfig->getValue(self::XML_PATH_2FA_LOCK_EXPIRE);
137-
if ($this->userResource->lock($user->getId(), 0, $lockThreshold)) {
138+
if ($this->userResource->lock((int)$user->getId(), 0, $lockThreshold)) {
138139
$response->setData(['success' => false, 'message' => "Your account is temporarily disabled."]);
139140
return $response;
140141
}

0 commit comments

Comments
 (0)