Skip to content

Commit 9f6f3cb

Browse files
glo23503o-dubovyk
authored andcommitted
ACP2E-3246: Customer API - Login Failures Number Not Able To Reset To 0 After Successful Login
1 parent 651928c commit 9f6f3cb

File tree

5 files changed

+25
-28
lines changed

5 files changed

+25
-28
lines changed

app/code/Magento/Customer/Model/Authentication.php

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
use Magento\Customer\Api\CustomerRepositoryInterface;
99
use Magento\Customer\Model\ResourceModel\CustomerRepository;
10-
use Magento\Customer\Model\CustomerAuthUpdate;
1110
use Magento\Backend\App\ConfigInterface;
11+
use Magento\Framework\App\ObjectManager;
1212
use Magento\Framework\Encryption\EncryptorInterface as Encryptor;
1313
use Magento\Framework\Exception\InvalidEmailOrPasswordException;
1414
use Magento\Framework\Exception\State\UserLockedException;
@@ -67,19 +67,22 @@ class Authentication implements AuthenticationInterface
6767
* @param ConfigInterface $backendConfig
6868
* @param \Magento\Framework\Stdlib\DateTime $dateTime
6969
* @param Encryptor $encryptor
70+
* @param CustomerAuthUpdate|null $customerAuthUpdate
7071
*/
7172
public function __construct(
7273
CustomerRepositoryInterface $customerRepository,
7374
CustomerRegistry $customerRegistry,
7475
ConfigInterface $backendConfig,
7576
\Magento\Framework\Stdlib\DateTime $dateTime,
76-
Encryptor $encryptor
77+
Encryptor $encryptor,
78+
CustomerAuthUpdate $customerAuthUpdate = null
7779
) {
7880
$this->customerRepository = $customerRepository;
7981
$this->customerRegistry = $customerRegistry;
8082
$this->backendConfig = $backendConfig;
8183
$this->dateTime = $dateTime;
8284
$this->encryptor = $encryptor;
85+
$this->customerAuthUpdate = $customerAuthUpdate ?: ObjectManager::getInstance()->get(CustomerAuthUpdate::class);
8386
}
8487

8588
/**
@@ -116,7 +119,7 @@ public function processAuthenticationFailure($customerId)
116119
}
117120

118121
$customerSecure->setFailuresNum($failuresNum);
119-
$this->getCustomerAuthUpdate()->saveAuth($customerId);
122+
$this->customerAuthUpdate->saveAuth($customerId);
120123
}
121124

122125
/**
@@ -128,7 +131,7 @@ public function unlock($customerId)
128131
$customerSecure->setFailuresNum(0);
129132
$customerSecure->setFirstFailure(null);
130133
$customerSecure->setLockExpires(null);
131-
$this->getCustomerAuthUpdate()->saveAuth($customerId);
134+
$this->customerAuthUpdate->saveAuth($customerId);
132135
}
133136

134137
/**
@@ -176,19 +179,4 @@ public function authenticate($customerId, $password)
176179
}
177180
return true;
178181
}
179-
180-
/**
181-
* Get customer authentication update model
182-
*
183-
* @return \Magento\Customer\Model\CustomerAuthUpdate
184-
* @deprecated 100.1.1
185-
*/
186-
private function getCustomerAuthUpdate()
187-
{
188-
if ($this->customerAuthUpdate === null) {
189-
$this->customerAuthUpdate =
190-
\Magento\Framework\App\ObjectManager::getInstance()->get(CustomerAuthUpdate::class);
191-
}
192-
return $this->customerAuthUpdate;
193-
}
194182
}

app/code/Magento/Customer/Model/CustomerAuthUpdate.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,23 @@ class CustomerAuthUpdate
2626
protected $customerResourceModel;
2727

2828
/**
29-
* @var Customer
29+
* @var CustomerFactory
3030
*/
31-
private $customerModel;
31+
private $customerFactory;
3232

3333
/**
3434
* @param CustomerRegistry $customerRegistry
3535
* @param CustomerResourceModel $customerResourceModel
36-
* @param Customer|null $customerModel
36+
* @param CustomerFactory|null $customerFactory
3737
*/
3838
public function __construct(
3939
CustomerRegistry $customerRegistry,
4040
CustomerResourceModel $customerResourceModel,
41-
Customer $customerModel = null
41+
CustomerFactory $customerFactory = null
4242
) {
4343
$this->customerRegistry = $customerRegistry;
4444
$this->customerResourceModel = $customerResourceModel;
45-
$this->customerModel = $customerModel ?: ObjectManager::getInstance()->get(Customer::class);
45+
$this->customerFactory = $customerFactory ?: ObjectManager::getInstance()->get(CustomerFactory::class);
4646
}
4747

4848
/**
@@ -55,9 +55,9 @@ public function __construct(
5555
public function saveAuth($customerId)
5656
{
5757
$customerSecure = $this->customerRegistry->retrieveSecureData($customerId);
58-
59-
$this->customerResourceModel->load($this->customerModel, $customerId);
60-
$currentLockExpiresVal = $this->customerModel->getData('lock_expires');
58+
$customerModel = $this->customerFactory->create();
59+
$this->customerResourceModel->load($customerModel, $customerId);
60+
$currentLockExpiresVal = $customerModel->getData('lock_expires');
6161
$newLockExpiresVal = $customerSecure->getData('lock_expires');
6262

6363
$this->customerResourceModel->getConnection()->update(
@@ -71,7 +71,7 @@ public function saveAuth($customerId)
7171
);
7272

7373
if ($currentLockExpiresVal !== $newLockExpiresVal) {
74-
$this->customerModel->reindex();
74+
$customerModel->reindex();
7575
}
7676

7777
return $this;

app/code/Magento/CustomerGraphQl/etc/graphql/events.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,7 @@
1010
<event name="customer_login">
1111
<observer name="customer_log_login" instance="Magento\Customer\Observer\LogLastLoginAtObserver" />
1212
</event>
13+
<event name="customer_customer_authenticated">
14+
<observer name="customer_unlock" instance="Magento\Customer\Observer\CustomerLoginSuccessObserver" />
15+
</event>
1316
</config>

app/code/Magento/Integration/etc/webapi_rest/events.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,7 @@
99
<event name="customer_login">
1010
<observer name="customer_log_login" instance="Magento\Customer\Observer\LogLastLoginAtObserver" />
1111
</event>
12+
<event name="customer_customer_authenticated">
13+
<observer name="customer_unlock" instance="Magento\Customer\Observer\CustomerLoginSuccessObserver" />
14+
</event>
1215
</config>

app/code/Magento/Integration/etc/webapi_soap/events.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,7 @@
99
<event name="customer_login">
1010
<observer name="customer_log_login" instance="Magento\Customer\Observer\LogLastLoginAtObserver" />
1111
</event>
12+
<event name="customer_customer_authenticated">
13+
<observer name="customer_unlock" instance="Magento\Customer\Observer\CustomerLoginSuccessObserver" />
14+
</event>
1215
</config>

0 commit comments

Comments
 (0)