19
19
namespace Magento \Customer \Model \AccountManagement ;
20
20
21
21
use Magento \Customer \Api \Data \CustomerInterface ;
22
- use Magento \Customer \Api \Data \CustomerInterfaceFactory ;
23
22
use Magento \Customer \Model \AccountConfirmation ;
24
23
use 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 ;
28
26
use Magento \Framework \Event \ManagerInterface ;
29
27
use Magento \Framework \Exception \EmailNotConfirmedException ;
30
28
use Magento \Framework \Exception \InvalidEmailOrPasswordException ;
40
38
class Authenticate
41
39
{
42
40
/**
43
- * @var CustomerRegistry
41
+ * @var CustomerRepository
44
42
*/
45
- private CustomerRegistry $ customerRegistry ;
43
+ private CustomerRepository $ customerRepository ;
46
44
47
45
/**
48
- * @var DataObjectHelper
46
+ * @var CustomerFactory
49
47
*/
50
- private DataObjectHelper $ dataObjectHelper ;
51
-
52
- /**
53
- * @var CustomerInterfaceFactory
54
- */
55
- private CustomerInterfaceFactory $ customerFactory ;
48
+ private CustomerFactory $ customerFactory ;
56
49
57
50
/**
58
51
* @var AuthenticationInterface
@@ -70,23 +63,20 @@ class Authenticate
70
63
private ManagerInterface $ eventManager ;
71
64
72
65
/**
73
- * @param CustomerRegistry $customerRegistry
74
- * @param DataObjectHelper $dataObjectHelper
75
- * @param CustomerInterfaceFactory $customerFactory
66
+ * @param CustomerRepository $customerRepository
67
+ * @param CustomerFactory $customerFactory
76
68
* @param AuthenticationInterface $authentication
77
69
* @param AccountConfirmation $accountConfirmation
78
70
* @param ManagerInterface $eventManager
79
71
*/
80
72
public function __construct (
81
- CustomerRegistry $ customerRegistry ,
82
- DataObjectHelper $ dataObjectHelper ,
83
- CustomerInterfaceFactory $ customerFactory ,
73
+ CustomerRepository $ customerRepository ,
74
+ CustomerFactory $ customerFactory ,
84
75
AuthenticationInterface $ authentication ,
85
76
AccountConfirmation $ accountConfirmation ,
86
77
ManagerInterface $ eventManager
87
78
) {
88
- $ this ->customerRegistry = $ customerRegistry ;
89
- $ this ->dataObjectHelper = $ dataObjectHelper ;
79
+ $ this ->customerRepository = $ customerRepository ;
90
80
$ this ->customerFactory = $ customerFactory ;
91
81
$ this ->authentication = $ authentication ;
92
82
$ this ->accountConfirmation = $ accountConfirmation ;
@@ -104,11 +94,10 @@ public function __construct(
104
94
public function execute (string $ email , string $ password ): CustomerInterface
105
95
{
106
96
try {
107
- $ customerModel = $ this ->customerRegistry -> retrieveByEmail ($ email );
97
+ $ customer = $ this ->customerRepository -> get ($ email );
108
98
} catch (NoSuchEntityException $ exception ) {
109
99
throw new InvalidEmailOrPasswordException (__ ('Invalid login or password. ' ));
110
100
}
111
- $ customer = $ this ->getCustomerDataObject ($ customerModel );
112
101
113
102
$ customerId = $ customer ->getId ();
114
103
if ($ this ->authentication ->isLocked ($ customerId )) {
@@ -125,6 +114,7 @@ public function execute(string $email, string $password): CustomerInterface
125
114
throw new EmailNotConfirmedException (__ ('This account isn \'t confirmed. Verify and try again. ' ));
126
115
}
127
116
117
+ $ customerModel = $ this ->customerFactory ->create ()->updateData ($ customer );
128
118
$ this ->eventManager ->dispatch (
129
119
'customer_customer_authenticated ' ,
130
120
['model ' => $ customerModel , 'password ' => $ password ]
@@ -135,24 +125,6 @@ public function execute(string $email, string $password): CustomerInterface
135
125
return $ customer ;
136
126
}
137
127
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
-
156
128
/**
157
129
* Check if accounts confirmation is required in config
158
130
*
0 commit comments