1313use Magento \Framework \Serialize \SerializerInterface ;
1414use Magento \Framework \Webapi \ServiceOutputProcessor ;
1515use Magento \Customer \Api \Data \CustomerInterface ;
16- use Magento \Newsletter \Model \SubscriberFactory ;
1716use Magento \Customer \Model \CustomerRegistry ;
1817use Magento \Framework \Encryption \EncryptorInterface as Encryptor ;
19- use Magento \Store \Api \StoreResolverInterface ;
20- use Magento \Framework \GraphQl \Exception \GraphQlAuthorizationException ;
2118
2219/**
2320 * Customer field data provider, used for GraphQL request processing.
@@ -34,16 +31,6 @@ class CustomerDataProvider
3431 */
3532 private $ serviceOutputProcessor ;
3633
37- /**
38- * @var StoreResolverInterface
39- */
40- private $ storeResolver ;
41-
42- /**
43- * @var \Magento\Newsletter\Model\SubscriberFactory
44- */
45- protected $ subscriberFactory ;
46-
4734 /**
4835 * @var CustomerRegistry
4936 */
@@ -68,31 +55,14 @@ public function __construct(
6855 CustomerRepositoryInterface $ customerRepository ,
6956 ServiceOutputProcessor $ serviceOutputProcessor ,
7057 SerializerInterface $ jsonSerializer ,
71- SubscriberFactory $ subscriberFactory ,
7258 CustomerRegistry $ customerRegistry ,
73- Encryptor $ encryptor ,
74- StoreResolverInterface $ storeResolver
59+ Encryptor $ encryptor
7560 ) {
7661 $ this ->customerRepository = $ customerRepository ;
7762 $ this ->serviceOutputProcessor = $ serviceOutputProcessor ;
7863 $ this ->jsonSerializer = $ jsonSerializer ;
79- $ this ->subscriberFactory = $ subscriberFactory ;
8064 $ this ->customerRegistry = $ customerRegistry ;
8165 $ 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 );
9666 }
9767
9868 /**
@@ -158,82 +128,14 @@ private function processCustomer(CustomerInterface $customerObject): array
158128 }
159129
160130 /**
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
175132 * @param int $customerId
176- * @param $newSubscriptionStatus
177133 * @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
197134 * @throws NoSuchEntityException
198- * @throws \Magento\Framework\Exception\InputException
199- * @throws \Magento\Framework\Exception\State\InputMismatchException
200135 */
201- public function updateAccountInformation ( int $ customerId , array $ customerData ): CustomerInterface
136+ public function isPasswordCorrect ( string $ password , int $ customerId )
202137 {
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 );
238140 }
239141}
0 commit comments