Skip to content

Commit 24c8b2e

Browse files
committed
MAGETWO-56126: Login failed after new custom attribute was added
- handling unlock with a specialized model that can save only auth data for the customer
1 parent 3878c00 commit 24c8b2e

File tree

3 files changed

+85
-106
lines changed

3 files changed

+85
-106
lines changed

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

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
*/
66
namespace Magento\Customer\Model;
77

8-
use Magento\Customer\Model\ResourceModel\CustomerAuthenticationRepository;
8+
use Magento\Customer\Model\ResourceModel\CustomerRepository;
9+
use Magento\Customer\Model\CustomerAuthUpdate;
910
use Magento\Backend\App\ConfigInterface;
1011
use Magento\Framework\Encryption\EncryptorInterface as Encryptor;
1112
use Magento\Framework\Exception\InvalidEmailOrPasswordException;
@@ -46,19 +47,24 @@ class Authentication implements AuthenticationInterface
4647
protected $encryptor;
4748

4849
/**
49-
* @var CustomerAuthenticationRepository
50+
* @var CustomerRepository
5051
*/
5152
protected $customerRepository;
5253

5354
/**
54-
* @param CustomerAuthenticationRepository $customerRepository
55+
* @var CustomerAuthUpdate
56+
*/
57+
private $customerAuthUpdate;
58+
59+
/**
60+
* @param CustomerRepository $customerRepository
5561
* @param CustomerRegistry $customerRegistry
5662
* @param ConfigInterface $backendConfig
5763
* @param \Magento\Framework\Stdlib\DateTime $dateTime
5864
* @param Encryptor $encryptor
5965
*/
6066
public function __construct(
61-
CustomerAuthenticationRepository $customerRepository,
67+
CustomerRepository $customerRepository,
6268
CustomerRegistry $customerRegistry,
6369
ConfigInterface $backendConfig,
6470
\Magento\Framework\Stdlib\DateTime $dateTime,
@@ -105,7 +111,7 @@ public function processAuthenticationFailure($customerId)
105111
}
106112

107113
$customerSecure->setFailuresNum($failuresNum);
108-
$this->customerRepository->save($this->customerRepository->getById($customerId));
114+
$this->getCustomerAuthUpdate()->saveAuth($customerId);
109115
}
110116

111117
/**
@@ -117,7 +123,7 @@ public function unlock($customerId)
117123
$customerSecure->setFailuresNum(0);
118124
$customerSecure->setFirstFailure(null);
119125
$customerSecure->setLockExpires(null);
120-
$this->customerRepository->save($this->customerRepository->getById($customerId));
126+
$this->getCustomerAuthUpdate()->saveAuth($customerId);
121127
}
122128

123129
/**
@@ -165,4 +171,19 @@ public function authenticate($customerId, $password)
165171
}
166172
return true;
167173
}
174+
175+
/**
176+
* Get customer authentication update model
177+
*
178+
* @return \Magento\Customer\Model\CustomerAuthUpdate
179+
* @deprecated
180+
*/
181+
private function getCustomerAuthUpdate()
182+
{
183+
if ($this->customerAuthUpdate === null) {
184+
$this->customerAuthUpdate =
185+
\Magento\Framework\App\ObjectManager::getInstance()->get(CustomerAuthUpdate::class);
186+
}
187+
return $this->customerAuthUpdate;
188+
}
168189
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Customer\Model;
8+
9+
/**
10+
* Customer Authentication update model.
11+
*/
12+
class CustomerAuthUpdate
13+
{
14+
/**
15+
* @var \Magento\Customer\Model\CustomerRegistry
16+
*/
17+
protected $customerRegistry;
18+
19+
/**
20+
* @var \Magento\Customer\Model\ResourceModel\Customer
21+
*/
22+
protected $customerResourceModel;
23+
24+
/**
25+
* @param \Magento\Customer\Model\CustomerRegistry $customerRegistry
26+
* @param \Magento\Customer\Model\ResourceModel\Customer $customerResourceModel
27+
*/
28+
public function __construct(
29+
\Magento\Customer\Model\CustomerRegistry $customerRegistry,
30+
\Magento\Customer\Model\ResourceModel\Customer $customerResourceModel
31+
) {
32+
$this->customerRegistry = $customerRegistry;
33+
$this->customerResourceModel = $customerResourceModel;
34+
}
35+
36+
/**
37+
* Reset Authentication data for customer.
38+
*
39+
* @param int $customerId
40+
* @return $this
41+
*/
42+
public function saveAuth($customerId)
43+
{
44+
$customerSecure = $this->customerRegistry->retrieveSecureData($customerId);
45+
46+
$this->customerResourceModel->getConnection()->update(
47+
$this->customerResourceModel->getTable('customer_entity'),
48+
array(
49+
'failures_num' => $customerSecure->getData('failures_num'),
50+
'first_failure' => $customerSecure->getData('first_failure'),
51+
'lock_expires' => $customerSecure->getData('lock_expires'),
52+
),
53+
$this->customerResourceModel->getConnection()->quoteInto('entity_id = ?', $customerId)
54+
);
55+
56+
return $this;
57+
}
58+
}

app/code/Magento/Customer/Model/ResourceModel/CustomerAuthenticationRepository.php

Lines changed: 0 additions & 100 deletions
This file was deleted.

0 commit comments

Comments
 (0)