13
13
use Magento \Framework \Serialize \SerializerInterface ;
14
14
use Magento \Framework \Webapi \ServiceOutputProcessor ;
15
15
use Magento \Customer \Api \Data \CustomerInterface ;
16
- use Magento \Newsletter \Model \SubscriberFactory ;
17
16
use Magento \Customer \Model \CustomerRegistry ;
18
17
use Magento \Framework \Encryption \EncryptorInterface as Encryptor ;
19
- use Magento \Store \Api \StoreResolverInterface ;
20
- use Magento \Framework \GraphQl \Exception \GraphQlAuthorizationException ;
21
18
22
19
/**
23
20
* Customer field data provider, used for GraphQL request processing.
@@ -34,16 +31,6 @@ class CustomerDataProvider
34
31
*/
35
32
private $ serviceOutputProcessor ;
36
33
37
- /**
38
- * @var StoreResolverInterface
39
- */
40
- private $ storeResolver ;
41
-
42
- /**
43
- * @var \Magento\Newsletter\Model\SubscriberFactory
44
- */
45
- protected $ subscriberFactory ;
46
-
47
34
/**
48
35
* @var CustomerRegistry
49
36
*/
@@ -68,31 +55,14 @@ public function __construct(
68
55
CustomerRepositoryInterface $ customerRepository ,
69
56
ServiceOutputProcessor $ serviceOutputProcessor ,
70
57
SerializerInterface $ jsonSerializer ,
71
- SubscriberFactory $ subscriberFactory ,
72
58
CustomerRegistry $ customerRegistry ,
73
- Encryptor $ encryptor ,
74
- StoreResolverInterface $ storeResolver
59
+ Encryptor $ encryptor
75
60
) {
76
61
$ this ->customerRepository = $ customerRepository ;
77
62
$ this ->serviceOutputProcessor = $ serviceOutputProcessor ;
78
63
$ this ->jsonSerializer = $ jsonSerializer ;
79
- $ this ->subscriberFactory = $ subscriberFactory ;
80
64
$ this ->customerRegistry = $ customerRegistry ;
81
65
$ this ->encryptor = $ encryptor ;
82
- $ this ->storeResolver = $ storeResolver ;
83
- }
84
-
85
- /**
86
- * Load customer object
87
- *
88
- * @param int $customerId
89
- * @return CustomerInterface
90
- * @throws LocalizedException
91
- * @throws NoSuchEntityException
92
- */
93
- public function loadCustomerById (int $ customerId ): CustomerInterface
94
- {
95
- return $ this ->customerRepository ->getById ($ customerId );
96
66
}
97
67
98
68
/**
@@ -158,82 +128,14 @@ private function processCustomer(CustomerInterface $customerObject): array
158
128
}
159
129
160
130
/**
161
- * Check if customer is subscribed to Newsletter
162
- *
163
- * @param int $customerId
164
- * @return bool
165
- */
166
- public function isSubscribed (int $ customerId ): bool
167
- {
168
- $ checkSubscriber = $ this ->subscriberFactory ->create ()->loadByCustomerId ($ customerId );
169
- return $ checkSubscriber ->isSubscribed ();
170
- }
171
-
172
- /**
173
- * Manage customer subscription. Subscribe OR unsubscribe if required
174
- *
131
+ * @param string $password
175
132
* @param int $customerId
176
- * @param $newSubscriptionStatus
177
133
* @return bool
178
- */
179
- public function manageSubscription (int $ customerId , bool $ newSubscriptionStatus ): bool
180
- {
181
- $ checkSubscriber = $ this ->subscriberFactory ->create ()->loadByCustomerId ($ customerId );
182
- $ isSubscribed = $ this ->isSubscribed ($ customerId );
183
-
184
- if ($ newSubscriptionStatus === true && !$ isSubscribed ) {
185
- $ this ->subscriberFactory ->create ()->subscribeCustomerById ($ customerId );
186
- } elseif ($ newSubscriptionStatus === false && $ checkSubscriber ->isSubscribed ()) {
187
- $ this ->subscriberFactory ->create ()->unsubscribeCustomerById ($ customerId );
188
- }
189
- return true ;
190
- }
191
-
192
- /**
193
- * @param int $customerId
194
- * @param array $customerData
195
- * @return CustomerInterface
196
- * @throws LocalizedException
197
134
* @throws NoSuchEntityException
198
- * @throws \Magento\Framework\Exception\InputException
199
- * @throws \Magento\Framework\Exception\State\InputMismatchException
200
135
*/
201
- public function updateAccountInformation ( int $ customerId , array $ customerData ): CustomerInterface
136
+ public function isPasswordCorrect ( string $ password , int $ customerId )
202
137
{
203
-
204
- $ customer = $ this ->loadCustomerById ($ customerId );
205
-
206
- if (isset ($ customerData ['email ' ])
207
- && $ customer ->getEmail () !== $ customerData ['email ' ]
208
- && isset ($ customerData ['password ' ])) {
209
- if ($ this ->isPasswordCorrect ($ customerData ['password ' ], $ customerId )) {
210
- $ customer ->setEmail ($ customerData ['email ' ]);
211
- } else {
212
- throw new GraphQlAuthorizationException (__ ('Invalid current user password. ' ));
213
- }
214
- }
215
-
216
- if (isset ($ customerData ['firstname ' ])) {
217
- $ customer ->setFirstname ($ customerData ['firstname ' ]);
218
- }
219
- if (isset ($ customerData ['lastname ' ])) {
220
- $ customer ->setLastname ($ customerData ['lastname ' ]);
221
- }
222
-
223
- $ customer ->setStoreId ($ this ->storeResolver ->getCurrentStoreId ());
224
- $ this ->customerRepository ->save ($ customer );
225
-
226
- return $ customer ;
227
- }
228
-
229
- private function isPasswordCorrect (string $ password , int $ customerId )
230
- {
231
-
232
- $ customerSecure = $ this ->customerRegistry ->retrieveSecureData ($ customerId );
233
- $ hash = $ customerSecure ->getPasswordHash ();
234
- if (!$ this ->encryptor ->validateHash ($ password , $ hash )) {
235
- return false ;
236
- }
237
- return true ;
138
+ $ hash = $ this ->customerRegistry ->retrieveSecureData ($ customerId )->getPasswordHash ();
139
+ return $ this ->encryptor ->validateHash ($ password , $ hash );
238
140
}
239
141
}
0 commit comments