Skip to content

Commit 3878c00

Browse files
committed
MAGETWO-56126: Login failed after new custom attribute was added
- handling unlock with a different repository as customer entity can't be used at this point because of data integrity vs validation per this bug
1 parent bcdd65f commit 3878c00

File tree

2 files changed

+104
-4
lines changed

2 files changed

+104
-4
lines changed

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

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

8-
use Magento\Customer\Api\CustomerRepositoryInterface;
8+
use Magento\Customer\Model\ResourceModel\CustomerAuthenticationRepository;
99
use Magento\Backend\App\ConfigInterface;
1010
use Magento\Framework\Encryption\EncryptorInterface as Encryptor;
1111
use Magento\Framework\Exception\InvalidEmailOrPasswordException;
@@ -46,19 +46,19 @@ class Authentication implements AuthenticationInterface
4646
protected $encryptor;
4747

4848
/**
49-
* @var CustomerRepositoryInterface
49+
* @var CustomerAuthenticationRepository
5050
*/
5151
protected $customerRepository;
5252

5353
/**
54-
* @param CustomerRepositoryInterface $customerRepository
54+
* @param CustomerAuthenticationRepository $customerRepository
5555
* @param CustomerRegistry $customerRegistry
5656
* @param ConfigInterface $backendConfig
5757
* @param \Magento\Framework\Stdlib\DateTime $dateTime
5858
* @param Encryptor $encryptor
5959
*/
6060
public function __construct(
61-
CustomerRepositoryInterface $customerRepository,
61+
CustomerAuthenticationRepository $customerRepository,
6262
CustomerRegistry $customerRegistry,
6363
ConfigInterface $backendConfig,
6464
\Magento\Framework\Stdlib\DateTime $dateTime,
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Customer\Model\ResourceModel;
8+
9+
/**
10+
* Customer repository.
11+
*/
12+
class CustomerAuthenticationRepository
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+
* @var \Magento\Framework\Event\ManagerInterface
26+
*/
27+
protected $eventManager;
28+
29+
/**
30+
* @param \Magento\Customer\Model\CustomerRegistry $customerRegistry
31+
* @param \Magento\Customer\Model\ResourceModel\Customer $customerResourceModel
32+
* @param \Magento\Framework\Event\ManagerInterface $eventManager
33+
*/
34+
public function __construct(
35+
\Magento\Customer\Model\CustomerRegistry $customerRegistry,
36+
\Magento\Customer\Model\ResourceModel\Customer $customerResourceModel,
37+
\Magento\Framework\Event\ManagerInterface $eventManager
38+
) {
39+
$this->customerRegistry = $customerRegistry;
40+
$this->customerResourceModel = $customerResourceModel;
41+
$this->eventManager = $eventManager;
42+
}
43+
44+
/**
45+
* Create or update a customer.
46+
*
47+
* @param \Magento\Customer\Api\Data\CustomerInterface $customer
48+
* @return \Magento\Customer\Api\Data\CustomerInterface
49+
*/
50+
public function save(\Magento\Customer\Api\Data\CustomerInterface $customer)
51+
{
52+
$customerSecure = $this->customerRegistry->retrieveSecureData($customer->getId());
53+
54+
$this->customerResourceModel->getConnection()->update(
55+
$this->customerResourceModel->getTable('customer_entity'),
56+
array(
57+
'failures_num' => $customerSecure->getData('failures_num'),
58+
'first_failure' => $customerSecure->getData('first_failure'),
59+
'lock_expires' => $customerSecure->getData('lock_expires'),
60+
),
61+
$this->customerResourceModel->getConnection()->quoteInto('entity_id = ?', $customer->getId())
62+
);
63+
64+
$savedCustomer = $this->get($customer->getEmail(), $customer->getWebsiteId());
65+
$this->eventManager->dispatch(
66+
'customer_save_after_data_object',
67+
['customer_data_object' => $savedCustomer, 'orig_customer_data_object' => $customer]
68+
);
69+
return $savedCustomer;
70+
}
71+
72+
/**
73+
* Retrieve customer.
74+
*
75+
* @param string $email
76+
* @param int|null $websiteId
77+
* @return \Magento\Customer\Api\Data\CustomerInterface
78+
* @throws \Magento\Framework\Exception\NoSuchEntityException If customer with the specified email does not exist.
79+
* @throws \Magento\Framework\Exception\LocalizedException
80+
*/
81+
public function get($email, $websiteId = null)
82+
{
83+
$customerModel = $this->customerRegistry->retrieveByEmail($email, $websiteId);
84+
return $customerModel->getDataModel();
85+
}
86+
87+
/**
88+
* Get customer by customer ID.
89+
*
90+
* @param int $customerId
91+
* @return \Magento\Customer\Api\Data\CustomerInterface
92+
* @throws \Magento\Framework\Exception\NoSuchEntityException If customer with the specified ID does not exist.
93+
* @throws \Magento\Framework\Exception\LocalizedException
94+
*/
95+
public function getById($customerId)
96+
{
97+
$customer = $this->customerRegistry->retrieve($customerId);
98+
return $customer->getDataModel();
99+
}
100+
}

0 commit comments

Comments
 (0)