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 ;
18
+ use Magento \Customer \Model \Customer \CredentialsValidator ;
19
19
use Magento \Customer \Model \Metadata \Validator ;
20
20
use Magento \Eav \Model \Validator \Attribute \Backend ;
21
21
use Magento \Framework \Api \ExtensibleDataObjectConverter ;
22
22
use Magento \Framework \App \Area ;
23
23
use Magento \Framework \App \Config \ScopeConfigInterface ;
24
24
use Magento \Framework \App \ObjectManager ;
25
+ use Magento \Framework \DataObjectFactory as ObjectFactory ;
25
26
use Magento \Framework \Encryption \EncryptorInterface as Encryptor ;
26
27
use Magento \Framework \Encryption \Helper \Security ;
27
28
use Magento \Framework \Event \ManagerInterface ;
30
31
use Magento \Framework \Exception \InputException ;
31
32
use Magento \Framework \Exception \InvalidEmailOrPasswordException ;
32
33
use Magento \Framework \Exception \LocalizedException ;
34
+ use Magento \Framework \Exception \MailException ;
33
35
use Magento \Framework \Exception \NoSuchEntityException ;
34
36
use Magento \Framework \Exception \State \ExpiredException ;
35
37
use Magento \Framework \Exception \State \InputMismatchException ;
36
38
use Magento \Framework \Exception \State \InvalidTransitionException ;
37
- use Magento \Framework \DataObjectFactory as ObjectFactory ;
38
39
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 ;
40
+ use Magento \Framework \Intl \DateTimeFactory ;
43
41
use Magento \Framework \Mail \Template \TransportBuilder ;
44
42
use Magento \Framework \Math \Random ;
45
43
use Magento \Framework \Reflection \DataObjectProcessor ;
44
+ use Magento \Framework \Registry ;
46
45
use Magento \Framework \Stdlib \DateTime ;
47
46
use Magento \Framework \Stdlib \StringUtils as StringHelper ;
47
+ use Magento \Store \Model \ScopeInterface ;
48
48
use Magento \Store \Model \StoreManagerInterface ;
49
- use Magento \ Customer \ Model \ Customer \ CredentialsValidator ;
49
+ use Psr \ Log \ LoggerInterface as PsrLogger ;
50
50
51
51
/**
52
52
* Handle various customer account actions
@@ -293,6 +293,11 @@ class AccountManagement implements AccountManagementInterface
293
293
*/
294
294
private $ credentialsValidator ;
295
295
296
+ /**
297
+ * @var DateTimeFactory
298
+ */
299
+ private $ dateTimeFactory ;
300
+
296
301
/**
297
302
* @param CustomerFactory $customerFactory
298
303
* @param ManagerInterface $eventManager
@@ -318,6 +323,7 @@ class AccountManagement implements AccountManagementInterface
318
323
* @param ObjectFactory $objectFactory
319
324
* @param ExtensibleDataObjectConverter $extensibleDataObjectConverter
320
325
* @param CredentialsValidator|null $credentialsValidator
326
+ * @param DateTimeFactory $dateTimeFactory
321
327
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
322
328
*/
323
329
public function __construct (
@@ -344,7 +350,8 @@ public function __construct(
344
350
CustomerModel $ customerModel ,
345
351
ObjectFactory $ objectFactory ,
346
352
ExtensibleDataObjectConverter $ extensibleDataObjectConverter ,
347
- CredentialsValidator $ credentialsValidator = null
353
+ CredentialsValidator $ credentialsValidator = null ,
354
+ DateTimeFactory $ dateTimeFactory = null
348
355
) {
349
356
$ this ->customerFactory = $ customerFactory ;
350
357
$ this ->eventManager = $ eventManager ;
@@ -369,8 +376,9 @@ public function __construct(
369
376
$ this ->customerModel = $ customerModel ;
370
377
$ this ->objectFactory = $ objectFactory ;
371
378
$ this ->extensibleDataObjectConverter = $ extensibleDataObjectConverter ;
372
- $ this ->credentialsValidator = $ credentialsValidator ?: ObjectManager::getInstance ()
373
- ->get (CredentialsValidator::class);
379
+ $ this ->credentialsValidator =
380
+ $ credentialsValidator ?: ObjectManager::getInstance ()->get (CredentialsValidator::class);
381
+ $ this ->dateTimeFactory = $ dateTimeFactory ?: ObjectManager::getInstance ()->get (DateTimeFactory::class);
374
382
}
375
383
376
384
/**
@@ -380,7 +388,6 @@ public function __construct(
380
388
*/
381
389
private function getAuthentication ()
382
390
{
383
-
384
391
if (!($ this ->authentication instanceof AuthenticationInterface)) {
385
392
return \Magento \Framework \App \ObjectManager::getInstance ()->get (
386
393
\Magento \Customer \Model \AuthenticationInterface::class
@@ -613,16 +620,16 @@ protected function makeRequiredCharactersCheck($password)
613
620
$ return = 0 ;
614
621
615
622
if (preg_match ('/[0-9]+/ ' , $ password )) {
616
- $ counter ++;
623
+ $ counter ++;
617
624
}
618
625
if (preg_match ('/[A-Z]+/ ' , $ password )) {
619
- $ counter ++;
626
+ $ counter ++;
620
627
}
621
628
if (preg_match ('/[a-z]+/ ' , $ password )) {
622
- $ counter ++;
629
+ $ counter ++;
623
630
}
624
631
if (preg_match ('/[^a-zA-Z0-9]+/ ' , $ password )) {
625
- $ counter ++;
632
+ $ counter ++;
626
633
}
627
634
628
635
if ($ counter < $ requiredNumber ) {
@@ -890,16 +897,14 @@ public function validate(CustomerInterface $customer)
890
897
891
898
$ result = $ this ->getEavValidator ()->isValid ($ customerModel );
892
899
if ($ result === false && is_array ($ this ->getEavValidator ()->getMessages ())) {
893
- return $ validationResults ->setIsValid (false )
894
- ->setMessages (
895
- call_user_func_array (
896
- 'array_merge ' ,
897
- $ this ->getEavValidator ()->getMessages ()
898
- )
899
- );
900
+ return $ validationResults ->setIsValid (false )->setMessages (
901
+ call_user_func_array (
902
+ 'array_merge ' ,
903
+ $ this ->getEavValidator ()->getMessages ()
904
+ )
905
+ );
900
906
}
901
- return $ validationResults ->setIsValid (true )
902
- ->setMessages ([]);
907
+ return $ validationResults ->setIsValid (true )->setMessages ([]);
903
908
}
904
909
905
910
/**
@@ -949,10 +954,12 @@ public function isCustomerInStore($customerWebsiteId, $storeId)
949
954
private function validateResetPasswordToken ($ customerId , $ resetPasswordLinkToken )
950
955
{
951
956
if (empty ($ customerId ) || $ customerId < 0 ) {
952
- throw new InputException (__ (
953
- 'Invalid value of "%value" provided for the %fieldName field. ' ,
954
- ['value ' => $ customerId , 'fieldName ' => 'customerId ' ]
955
- ));
957
+ throw new InputException (
958
+ __ (
959
+ 'Invalid value of "%value" provided for the %fieldName field. ' ,
960
+ ['value ' => $ customerId , 'fieldName ' => 'customerId ' ]
961
+ )
962
+ );
956
963
}
957
964
if (!is_string ($ resetPasswordLinkToken ) || empty ($ resetPasswordLinkToken )) {
958
965
$ params = ['fieldName ' => 'resetPasswordLinkToken ' ];
@@ -1178,8 +1185,8 @@ public function isResetPasswordLinkTokenExpired($rpToken, $rpTokenCreatedAt)
1178
1185
1179
1186
$ expirationPeriod = $ this ->customerModel ->getResetPasswordLinkExpirationPeriod ();
1180
1187
1181
- $ currentTimestamp = ( new \ DateTime () )->getTimestamp ();
1182
- $ tokenTimestamp = ( new \ DateTime ( $ rpTokenCreatedAt) )->getTimestamp ();
1188
+ $ currentTimestamp = $ this -> dateTimeFactory -> create ( )->getTimestamp ();
1189
+ $ tokenTimestamp = $ this -> dateTimeFactory -> create ( $ rpTokenCreatedAt )->getTimestamp ();
1183
1190
if ($ tokenTimestamp > $ currentTimestamp ) {
1184
1191
return true ;
1185
1192
}
@@ -1215,7 +1222,9 @@ public function changeResetPasswordLinkToken($customer, $passwordLinkToken)
1215
1222
if (is_string ($ passwordLinkToken ) && !empty ($ passwordLinkToken )) {
1216
1223
$ customerSecure = $ this ->customerRegistry ->retrieveSecureData ($ customer ->getId ());
1217
1224
$ customerSecure ->setRpToken ($ passwordLinkToken );
1218
- $ customerSecure ->setRpTokenCreatedAt ((new \DateTime ())->format (DateTime::DATETIME_PHP_FORMAT ));
1225
+ $ customerSecure ->setRpTokenCreatedAt (
1226
+ $ this ->dateTimeFactory ->create ()->format (DateTime::DATETIME_PHP_FORMAT )
1227
+ );
1219
1228
$ this ->customerRepository ->save ($ customer );
1220
1229
}
1221
1230
return true ;
@@ -1304,8 +1313,8 @@ protected function getFullCustomerObject($customer)
1304
1313
// No need to flatten the custom attributes or nested objects since the only usage is for email templates and
1305
1314
// object passed for events
1306
1315
$ mergedCustomerData = $ this ->customerRegistry ->retrieveSecureData ($ customer ->getId ());
1307
- $ customerData = $ this -> dataProcessor
1308
- ->buildOutputDataArray ($ customer , \Magento \Customer \Api \Data \CustomerInterface::class);
1316
+ $ customerData =
1317
+ $ this -> dataProcessor ->buildOutputDataArray ($ customer , \Magento \Customer \Api \Data \CustomerInterface::class);
1309
1318
$ mergedCustomerData ->addData ($ customerData );
1310
1319
$ mergedCustomerData ->setData ('name ' , $ this ->customerViewHelper ->getCustomerName ($ customer ));
1311
1320
return $ mergedCustomerData ;
0 commit comments