12
12
use Magento \Customer \Api \Data \AddressInterface ;
13
13
use Magento \Customer \Api \Data \CustomerInterface ;
14
14
use Magento \Customer \Api \Data \ValidationResultsInterfaceFactory ;
15
- use Magento \Customer \Model \EmailNotificationInterface ;
16
15
use Magento \Customer \Helper \View as CustomerViewHelper ;
17
16
use Magento \Customer \Model \Config \Share as ConfigShare ;
18
17
use Magento \Customer \Model \Customer as CustomerModel ;
22
21
use Magento \Framework \App \Area ;
23
22
use Magento \Framework \App \Config \ScopeConfigInterface ;
24
23
use Magento \Framework \App \ObjectManager ;
24
+ use Magento \Framework \DataObjectFactory as ObjectFactory ;
25
25
use Magento \Framework \Encryption \EncryptorInterface as Encryptor ;
26
26
use Magento \Framework \Encryption \Helper \Security ;
27
27
use Magento \Framework \Event \ManagerInterface ;
30
30
use Magento \Framework \Exception \InputException ;
31
31
use Magento \Framework \Exception \InvalidEmailOrPasswordException ;
32
32
use Magento \Framework \Exception \LocalizedException ;
33
+ use Magento \Framework \Exception \MailException ;
33
34
use Magento \Framework \Exception \NoSuchEntityException ;
34
35
use Magento \Framework \Exception \State \ExpiredException ;
35
36
use Magento \Framework \Exception \State \InputMismatchException ;
36
37
use Magento \Framework \Exception \State \InvalidTransitionException ;
37
- use Magento \Framework \DataObjectFactory as ObjectFactory ;
38
38
use Magento \Framework \Exception \State \UserLockedException ;
39
- use Magento \Framework \Registry ;
40
- use Magento \Store \Model \ScopeInterface ;
41
- use Psr \Log \LoggerInterface as PsrLogger ;
42
- use Magento \Framework \Exception \MailException ;
39
+ use Magento \Framework \Intl \DateTimeFactory ;
43
40
use Magento \Framework \Mail \Template \TransportBuilder ;
44
41
use Magento \Framework \Math \Random ;
45
42
use Magento \Framework \Reflection \DataObjectProcessor ;
43
+ use Magento \Framework \Registry ;
46
44
use Magento \Framework \Stdlib \DateTime ;
47
45
use Magento \Framework \Stdlib \StringUtils as StringHelper ;
46
+ use Magento \Store \Model \ScopeInterface ;
48
47
use Magento \Store \Model \StoreManagerInterface ;
48
+ use Psr \Log \LoggerInterface as PsrLogger ;
49
49
50
50
/**
51
51
* Handle various customer account actions
@@ -287,6 +287,11 @@ class AccountManagement implements AccountManagementInterface
287
287
*/
288
288
private $ eavValidator ;
289
289
290
+ /**
291
+ * @var DateTimeFactory
292
+ */
293
+ private $ dateTimeFactory ;
294
+
290
295
/**
291
296
* @param CustomerFactory $customerFactory
292
297
* @param ManagerInterface $eventManager
@@ -311,6 +316,7 @@ class AccountManagement implements AccountManagementInterface
311
316
* @param CustomerModel $customerModel
312
317
* @param ObjectFactory $objectFactory
313
318
* @param ExtensibleDataObjectConverter $extensibleDataObjectConverter
319
+ * @param DateTimeFactory $dateTimeFactory
314
320
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
315
321
*/
316
322
public function __construct (
@@ -336,7 +342,8 @@ public function __construct(
336
342
DateTime $ dateTime ,
337
343
CustomerModel $ customerModel ,
338
344
ObjectFactory $ objectFactory ,
339
- ExtensibleDataObjectConverter $ extensibleDataObjectConverter
345
+ ExtensibleDataObjectConverter $ extensibleDataObjectConverter ,
346
+ DateTimeFactory $ dateTimeFactory = null
340
347
) {
341
348
$ this ->customerFactory = $ customerFactory ;
342
349
$ this ->eventManager = $ eventManager ;
@@ -361,6 +368,7 @@ public function __construct(
361
368
$ this ->customerModel = $ customerModel ;
362
369
$ this ->objectFactory = $ objectFactory ;
363
370
$ this ->extensibleDataObjectConverter = $ extensibleDataObjectConverter ;
371
+ $ this ->dateTimeFactory = $ dateTimeFactory ?: ObjectManager::getInstance ()->get (DateTimeFactory::class);
364
372
}
365
373
366
374
/**
@@ -370,7 +378,6 @@ public function __construct(
370
378
*/
371
379
private function getAuthentication ()
372
380
{
373
-
374
381
if (!($ this ->authentication instanceof AuthenticationInterface)) {
375
382
return \Magento \Framework \App \ObjectManager::getInstance ()->get (
376
383
\Magento \Customer \Model \AuthenticationInterface::class
@@ -603,16 +610,16 @@ protected function makeRequiredCharactersCheck($password)
603
610
$ return = 0 ;
604
611
605
612
if (preg_match ('/[0-9]+/ ' , $ password )) {
606
- $ counter ++;
613
+ $ counter ++;
607
614
}
608
615
if (preg_match ('/[A-Z]+/ ' , $ password )) {
609
- $ counter ++;
616
+ $ counter ++;
610
617
}
611
618
if (preg_match ('/[a-z]+/ ' , $ password )) {
612
- $ counter ++;
619
+ $ counter ++;
613
620
}
614
621
if (preg_match ('/[^a-zA-Z0-9]+/ ' , $ password )) {
615
- $ counter ++;
622
+ $ counter ++;
616
623
}
617
624
618
625
if ($ counter < $ requiredNumber ) {
@@ -717,12 +724,12 @@ public function createAccountWithPasswordHash(CustomerInterface $customer, $hash
717
724
}
718
725
try {
719
726
foreach ($ customerAddresses as $ address ) {
720
- if ($ address ->getId ()) {
727
+ if ($ address ->getId ()) {
721
728
$ newAddress = clone $ address ;
722
729
$ newAddress ->setId (null );
723
730
$ newAddress ->setCustomerId ($ customer ->getId ());
724
731
$ this ->addressRepository ->save ($ newAddress );
725
- } else {
732
+ } else {
726
733
$ address ->setCustomerId ($ customer ->getId ());
727
734
$ this ->addressRepository ->save ($ address );
728
735
}
@@ -871,16 +878,14 @@ public function validate(CustomerInterface $customer)
871
878
872
879
$ result = $ this ->getEavValidator ()->isValid ($ customerModel );
873
880
if ($ result === false && is_array ($ this ->getEavValidator ()->getMessages ())) {
874
- return $ validationResults ->setIsValid (false )
875
- ->setMessages (
876
- call_user_func_array (
877
- 'array_merge ' ,
878
- $ this ->getEavValidator ()->getMessages ()
879
- )
880
- );
881
+ return $ validationResults ->setIsValid (false )->setMessages (
882
+ call_user_func_array (
883
+ 'array_merge ' ,
884
+ $ this ->getEavValidator ()->getMessages ()
885
+ )
886
+ );
881
887
}
882
- return $ validationResults ->setIsValid (true )
883
- ->setMessages ([]);
888
+ return $ validationResults ->setIsValid (true )->setMessages ([]);
884
889
}
885
890
886
891
/**
@@ -930,10 +935,12 @@ public function isCustomerInStore($customerWebsiteId, $storeId)
930
935
private function validateResetPasswordToken ($ customerId , $ resetPasswordLinkToken )
931
936
{
932
937
if (empty ($ customerId ) || $ customerId < 0 ) {
933
- throw new InputException (__ (
934
- 'Invalid value of "%value" provided for the %fieldName field. ' ,
935
- ['value ' => $ customerId , 'fieldName ' => 'customerId ' ]
936
- ));
938
+ throw new InputException (
939
+ __ (
940
+ 'Invalid value of "%value" provided for the %fieldName field. ' ,
941
+ ['value ' => $ customerId , 'fieldName ' => 'customerId ' ]
942
+ )
943
+ );
937
944
}
938
945
if (!is_string ($ resetPasswordLinkToken ) || empty ($ resetPasswordLinkToken )) {
939
946
$ params = ['fieldName ' => 'resetPasswordLinkToken ' ];
@@ -1090,12 +1097,11 @@ protected function sendEmailTemplate(
1090
1097
$ email = $ customer ->getEmail ();
1091
1098
}
1092
1099
1093
- $ transport = $ this ->transportBuilder ->setTemplateIdentifier ($ templateId )
1094
- ->setTemplateOptions (['area ' => Area::AREA_FRONTEND , 'store ' => $ storeId ])
1095
- ->setTemplateVars ($ templateParams )
1096
- ->setFrom ($ this ->scopeConfig ->getValue ($ sender , ScopeInterface::SCOPE_STORE , $ storeId ))
1097
- ->addTo ($ email , $ this ->customerViewHelper ->getCustomerName ($ customer ))
1098
- ->getTransport ();
1100
+ $ transport = $ this ->transportBuilder ->setTemplateIdentifier ($ templateId )->setTemplateOptions (
1101
+ ['area ' => Area::AREA_FRONTEND , 'store ' => $ storeId ]
1102
+ )->setTemplateVars ($ templateParams )->setFrom (
1103
+ $ this ->scopeConfig ->getValue ($ sender , ScopeInterface::SCOPE_STORE , $ storeId )
1104
+ )->addTo ($ email , $ this ->customerViewHelper ->getCustomerName ($ customer ))->getTransport ();
1099
1105
1100
1106
$ transport ->sendMessage ();
1101
1107
@@ -1159,8 +1165,8 @@ public function isResetPasswordLinkTokenExpired($rpToken, $rpTokenCreatedAt)
1159
1165
1160
1166
$ expirationPeriod = $ this ->customerModel ->getResetPasswordLinkExpirationPeriod ();
1161
1167
1162
- $ currentTimestamp = ( new \ DateTime () )->getTimestamp ();
1163
- $ tokenTimestamp = ( new \ DateTime ( $ rpTokenCreatedAt) )->getTimestamp ();
1168
+ $ currentTimestamp = $ this -> dateTimeFactory -> create ( )->getTimestamp ();
1169
+ $ tokenTimestamp = $ this -> dateTimeFactory -> create ( $ rpTokenCreatedAt )->getTimestamp ();
1164
1170
if ($ tokenTimestamp > $ currentTimestamp ) {
1165
1171
return true ;
1166
1172
}
@@ -1196,7 +1202,9 @@ public function changeResetPasswordLinkToken($customer, $passwordLinkToken)
1196
1202
if (is_string ($ passwordLinkToken ) && !empty ($ passwordLinkToken )) {
1197
1203
$ customerSecure = $ this ->customerRegistry ->retrieveSecureData ($ customer ->getId ());
1198
1204
$ customerSecure ->setRpToken ($ passwordLinkToken );
1199
- $ customerSecure ->setRpTokenCreatedAt ((new \DateTime ())->format (DateTime::DATETIME_PHP_FORMAT ));
1205
+ $ customerSecure ->setRpTokenCreatedAt (
1206
+ $ this ->dateTimeFactory ->create ()->format (DateTime::DATETIME_PHP_FORMAT )
1207
+ );
1200
1208
$ this ->customerRepository ->save ($ customer );
1201
1209
}
1202
1210
return true ;
@@ -1285,8 +1293,8 @@ protected function getFullCustomerObject($customer)
1285
1293
// No need to flatten the custom attributes or nested objects since the only usage is for email templates and
1286
1294
// object passed for events
1287
1295
$ mergedCustomerData = $ this ->customerRegistry ->retrieveSecureData ($ customer ->getId ());
1288
- $ customerData = $ this -> dataProcessor
1289
- ->buildOutputDataArray ($ customer , '\Magento\Customer\Api\Data\CustomerInterface ' );
1296
+ $ customerData =
1297
+ $ this -> dataProcessor ->buildOutputDataArray ($ customer , '\Magento\Customer\Api\Data\CustomerInterface ' );
1290
1298
$ mergedCustomerData ->addData ($ customerData );
1291
1299
$ mergedCustomerData ->setData ('name ' , $ this ->customerViewHelper ->getCustomerName ($ customer ));
1292
1300
return $ mergedCustomerData ;
0 commit comments