1919namespace Magento \Customer \Model \AccountManagement ;
2020
2121use Magento \Customer \Api \Data \CustomerInterface ;
22- use Magento \Customer \Api \Data \CustomerInterfaceFactory ;
2322use Magento \Customer \Model \AccountConfirmation ;
2423use Magento \Customer \Model \AuthenticationInterface ;
25- use Magento \Customer \Model \Customer ;
26- use Magento \Customer \Model \CustomerRegistry ;
27- use Magento \Framework \Api \DataObjectHelper ;
24+ use Magento \Customer \Model \CustomerFactory ;
25+ use Magento \Customer \Model \ResourceModel \CustomerRepository ;
2826use Magento \Framework \Event \ManagerInterface ;
2927use Magento \Framework \Exception \EmailNotConfirmedException ;
3028use Magento \Framework \Exception \InvalidEmailOrPasswordException ;
4038class Authenticate
4139{
4240 /**
43- * @var CustomerRegistry
41+ * @var CustomerRepository
4442 */
45- private CustomerRegistry $ customerRegistry ;
43+ private CustomerRepository $ customerRepository ;
4644
4745 /**
48- * @var DataObjectHelper
46+ * @var CustomerFactory
4947 */
50- private DataObjectHelper $ dataObjectHelper ;
51-
52- /**
53- * @var CustomerInterfaceFactory
54- */
55- private CustomerInterfaceFactory $ customerFactory ;
48+ private CustomerFactory $ customerFactory ;
5649
5750 /**
5851 * @var AuthenticationInterface
@@ -70,23 +63,20 @@ class Authenticate
7063 private ManagerInterface $ eventManager ;
7164
7265 /**
73- * @param CustomerRegistry $customerRegistry
74- * @param DataObjectHelper $dataObjectHelper
75- * @param CustomerInterfaceFactory $customerFactory
66+ * @param CustomerRepository $customerRepository
67+ * @param CustomerFactory $customerFactory
7668 * @param AuthenticationInterface $authentication
7769 * @param AccountConfirmation $accountConfirmation
7870 * @param ManagerInterface $eventManager
7971 */
8072 public function __construct (
81- CustomerRegistry $ customerRegistry ,
82- DataObjectHelper $ dataObjectHelper ,
83- CustomerInterfaceFactory $ customerFactory ,
73+ CustomerRepository $ customerRepository ,
74+ CustomerFactory $ customerFactory ,
8475 AuthenticationInterface $ authentication ,
8576 AccountConfirmation $ accountConfirmation ,
8677 ManagerInterface $ eventManager
8778 ) {
88- $ this ->customerRegistry = $ customerRegistry ;
89- $ this ->dataObjectHelper = $ dataObjectHelper ;
79+ $ this ->customerRepository = $ customerRepository ;
9080 $ this ->customerFactory = $ customerFactory ;
9181 $ this ->authentication = $ authentication ;
9282 $ this ->accountConfirmation = $ accountConfirmation ;
@@ -104,11 +94,10 @@ public function __construct(
10494 public function execute (string $ email , string $ password ): CustomerInterface
10595 {
10696 try {
107- $ customerModel = $ this ->customerRegistry -> retrieveByEmail ($ email );
97+ $ customer = $ this ->customerRepository -> get ($ email );
10898 } catch (NoSuchEntityException $ exception ) {
10999 throw new InvalidEmailOrPasswordException (__ ('Invalid login or password. ' ));
110100 }
111- $ customer = $ this ->getCustomerDataObject ($ customerModel );
112101
113102 $ customerId = $ customer ->getId ();
114103 if ($ this ->authentication ->isLocked ($ customerId )) {
@@ -125,6 +114,7 @@ public function execute(string $email, string $password): CustomerInterface
125114 throw new EmailNotConfirmedException (__ ('This account isn \'t confirmed. Verify and try again. ' ));
126115 }
127116
117+ $ customerModel = $ this ->customerFactory ->create ()->updateData ($ customer );
128118 $ this ->eventManager ->dispatch (
129119 'customer_customer_authenticated ' ,
130120 ['model ' => $ customerModel , 'password ' => $ password ]
@@ -135,24 +125,6 @@ public function execute(string $email, string $password): CustomerInterface
135125 return $ customer ;
136126 }
137127
138- /**
139- * Convert custom model to DTO
140- *
141- * @param Customer $customerModel
142- * @return CustomerInterface
143- */
144- private function getCustomerDataObject (Customer $ customerModel ): CustomerInterface
145- {
146- $ customerDataObject = $ this ->customerFactory ->create ();
147- $ this ->dataObjectHelper ->populateWithArray (
148- $ customerDataObject ,
149- $ customerModel ->getData (),
150- CustomerInterface::class
151- );
152- $ customerDataObject ->setId ($ customerModel ->getId ());
153- return $ customerDataObject ;
154- }
155-
156128 /**
157129 * Check if accounts confirmation is required in config
158130 *
0 commit comments