1212use Magento \Customer \Api \Data \AddressInterface ;
1313use Magento \Customer \Api \Data \CustomerInterface ;
1414use Magento \Customer \Api \Data \ValidationResultsInterfaceFactory ;
15- use Magento \Customer \Model \EmailNotificationInterface ;
1615use Magento \Customer \Helper \View as CustomerViewHelper ;
1716use Magento \Customer \Model \Config \Share as ConfigShare ;
1817use Magento \Customer \Model \Customer as CustomerModel ;
18+ use Magento \Customer \Model \Customer \CredentialsValidator ;
1919use Magento \Customer \Model \Metadata \Validator ;
2020use Magento \Eav \Model \Validator \Attribute \Backend ;
2121use Magento \Framework \Api \ExtensibleDataObjectConverter ;
2222use Magento \Framework \App \Area ;
2323use Magento \Framework \App \Config \ScopeConfigInterface ;
2424use Magento \Framework \App \ObjectManager ;
25+ use Magento \Framework \DataObjectFactory as ObjectFactory ;
2526use Magento \Framework \Encryption \EncryptorInterface as Encryptor ;
2627use Magento \Framework \Encryption \Helper \Security ;
2728use Magento \Framework \Event \ManagerInterface ;
3031use Magento \Framework \Exception \InputException ;
3132use Magento \Framework \Exception \InvalidEmailOrPasswordException ;
3233use Magento \Framework \Exception \LocalizedException ;
34+ use Magento \Framework \Exception \MailException ;
3335use Magento \Framework \Exception \NoSuchEntityException ;
3436use Magento \Framework \Exception \State \ExpiredException ;
3537use Magento \Framework \Exception \State \InputMismatchException ;
3638use Magento \Framework \Exception \State \InvalidTransitionException ;
37- use Magento \Framework \DataObjectFactory as ObjectFactory ;
3839use 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 ;
4341use Magento \Framework \Mail \Template \TransportBuilder ;
4442use Magento \Framework \Math \Random ;
4543use Magento \Framework \Reflection \DataObjectProcessor ;
44+ use Magento \Framework \Registry ;
4645use Magento \Framework \Stdlib \DateTime ;
4746use Magento \Framework \Stdlib \StringUtils as StringHelper ;
47+ use Magento \Store \Model \ScopeInterface ;
4848use Magento \Store \Model \StoreManagerInterface ;
49- use Magento \ Customer \ Model \ Customer \ CredentialsValidator ;
49+ use Psr \ Log \ LoggerInterface as PsrLogger ;
5050
5151/**
5252 * Handle various customer account actions
@@ -293,6 +293,11 @@ class AccountManagement implements AccountManagementInterface
293293 */
294294 private $ credentialsValidator ;
295295
296+ /**
297+ * @var DateTimeFactory
298+ */
299+ private $ dateTimeFactory ;
300+
296301 /**
297302 * @param CustomerFactory $customerFactory
298303 * @param ManagerInterface $eventManager
@@ -318,6 +323,7 @@ class AccountManagement implements AccountManagementInterface
318323 * @param ObjectFactory $objectFactory
319324 * @param ExtensibleDataObjectConverter $extensibleDataObjectConverter
320325 * @param CredentialsValidator|null $credentialsValidator
326+ * @param DateTimeFactory $dateTimeFactory
321327 * @SuppressWarnings(PHPMD.ExcessiveParameterList)
322328 */
323329 public function __construct (
@@ -344,7 +350,8 @@ public function __construct(
344350 CustomerModel $ customerModel ,
345351 ObjectFactory $ objectFactory ,
346352 ExtensibleDataObjectConverter $ extensibleDataObjectConverter ,
347- CredentialsValidator $ credentialsValidator = null
353+ CredentialsValidator $ credentialsValidator = null ,
354+ DateTimeFactory $ dateTimeFactory = null
348355 ) {
349356 $ this ->customerFactory = $ customerFactory ;
350357 $ this ->eventManager = $ eventManager ;
@@ -369,8 +376,9 @@ public function __construct(
369376 $ this ->customerModel = $ customerModel ;
370377 $ this ->objectFactory = $ objectFactory ;
371378 $ 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);
374382 }
375383
376384 /**
@@ -380,7 +388,6 @@ public function __construct(
380388 */
381389 private function getAuthentication ()
382390 {
383-
384391 if (!($ this ->authentication instanceof AuthenticationInterface)) {
385392 return \Magento \Framework \App \ObjectManager::getInstance ()->get (
386393 \Magento \Customer \Model \AuthenticationInterface::class
@@ -613,16 +620,16 @@ protected function makeRequiredCharactersCheck($password)
613620 $ return = 0 ;
614621
615622 if (preg_match ('/[0-9]+/ ' , $ password )) {
616- $ counter ++;
623+ $ counter ++;
617624 }
618625 if (preg_match ('/[A-Z]+/ ' , $ password )) {
619- $ counter ++;
626+ $ counter ++;
620627 }
621628 if (preg_match ('/[a-z]+/ ' , $ password )) {
622- $ counter ++;
629+ $ counter ++;
623630 }
624631 if (preg_match ('/[^a-zA-Z0-9]+/ ' , $ password )) {
625- $ counter ++;
632+ $ counter ++;
626633 }
627634
628635 if ($ counter < $ requiredNumber ) {
@@ -890,16 +897,14 @@ public function validate(CustomerInterface $customer)
890897
891898 $ result = $ this ->getEavValidator ()->isValid ($ customerModel );
892899 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+ );
900906 }
901- return $ validationResults ->setIsValid (true )
902- ->setMessages ([]);
907+ return $ validationResults ->setIsValid (true )->setMessages ([]);
903908 }
904909
905910 /**
@@ -949,10 +954,12 @@ public function isCustomerInStore($customerWebsiteId, $storeId)
949954 private function validateResetPasswordToken ($ customerId , $ resetPasswordLinkToken )
950955 {
951956 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+ );
956963 }
957964 if (!is_string ($ resetPasswordLinkToken ) || empty ($ resetPasswordLinkToken )) {
958965 $ params = ['fieldName ' => 'resetPasswordLinkToken ' ];
@@ -1076,10 +1083,10 @@ protected function getTemplateTypes()
10761083 * self::NEW_ACCOUNT_EMAIL_CONFIRMATION email with confirmation link
10771084 */
10781085 $ types = [
1079- self ::NEW_ACCOUNT_EMAIL_REGISTERED => self ::XML_PATH_REGISTER_EMAIL_TEMPLATE ,
1086+ self ::NEW_ACCOUNT_EMAIL_REGISTERED => self ::XML_PATH_REGISTER_EMAIL_TEMPLATE ,
10801087 self ::NEW_ACCOUNT_EMAIL_REGISTERED_NO_PASSWORD => self ::XML_PATH_REGISTER_NO_PASSWORD_EMAIL_TEMPLATE ,
1081- self ::NEW_ACCOUNT_EMAIL_CONFIRMED => self ::XML_PATH_CONFIRMED_EMAIL_TEMPLATE ,
1082- self ::NEW_ACCOUNT_EMAIL_CONFIRMATION => self ::XML_PATH_CONFIRM_EMAIL_TEMPLATE ,
1088+ self ::NEW_ACCOUNT_EMAIL_CONFIRMED => self ::XML_PATH_CONFIRMED_EMAIL_TEMPLATE ,
1089+ self ::NEW_ACCOUNT_EMAIL_CONFIRMATION => self ::XML_PATH_CONFIRM_EMAIL_TEMPLATE ,
10831090 ];
10841091 return $ types ;
10851092 }
@@ -1109,12 +1116,11 @@ protected function sendEmailTemplate(
11091116 $ email = $ customer ->getEmail ();
11101117 }
11111118
1112- $ transport = $ this ->transportBuilder ->setTemplateIdentifier ($ templateId )
1113- ->setTemplateOptions (['area ' => Area::AREA_FRONTEND , 'store ' => $ storeId ])
1114- ->setTemplateVars ($ templateParams )
1115- ->setFrom ($ this ->scopeConfig ->getValue ($ sender , ScopeInterface::SCOPE_STORE , $ storeId ))
1116- ->addTo ($ email , $ this ->customerViewHelper ->getCustomerName ($ customer ))
1117- ->getTransport ();
1119+ $ transport = $ this ->transportBuilder ->setTemplateIdentifier ($ templateId )->setTemplateOptions (
1120+ ['area ' => Area::AREA_FRONTEND , 'store ' => $ storeId ]
1121+ )->setTemplateVars ($ templateParams )->setFrom (
1122+ $ this ->scopeConfig ->getValue ($ sender , ScopeInterface::SCOPE_STORE , $ storeId )
1123+ )->addTo ($ email , $ this ->customerViewHelper ->getCustomerName ($ customer ))->getTransport ();
11181124
11191125 $ transport ->sendMessage ();
11201126
@@ -1178,8 +1184,8 @@ public function isResetPasswordLinkTokenExpired($rpToken, $rpTokenCreatedAt)
11781184
11791185 $ expirationPeriod = $ this ->customerModel ->getResetPasswordLinkExpirationPeriod ();
11801186
1181- $ currentTimestamp = ( new \ DateTime () )->getTimestamp ();
1182- $ tokenTimestamp = ( new \ DateTime ( $ rpTokenCreatedAt) )->getTimestamp ();
1187+ $ currentTimestamp = $ this -> dateTimeFactory -> create ( )->getTimestamp ();
1188+ $ tokenTimestamp = $ this -> dateTimeFactory -> create ( $ rpTokenCreatedAt )->getTimestamp ();
11831189 if ($ tokenTimestamp > $ currentTimestamp ) {
11841190 return true ;
11851191 }
@@ -1215,7 +1221,9 @@ public function changeResetPasswordLinkToken($customer, $passwordLinkToken)
12151221 if (is_string ($ passwordLinkToken ) && !empty ($ passwordLinkToken )) {
12161222 $ customerSecure = $ this ->customerRegistry ->retrieveSecureData ($ customer ->getId ());
12171223 $ customerSecure ->setRpToken ($ passwordLinkToken );
1218- $ customerSecure ->setRpTokenCreatedAt ((new \DateTime ())->format (DateTime::DATETIME_PHP_FORMAT ));
1224+ $ customerSecure ->setRpTokenCreatedAt (
1225+ $ this ->dateTimeFactory ->create ()->format (DateTime::DATETIME_PHP_FORMAT )
1226+ );
12191227 $ this ->customerRepository ->save ($ customer );
12201228 }
12211229 return true ;
@@ -1304,8 +1312,8 @@ protected function getFullCustomerObject($customer)
13041312 // No need to flatten the custom attributes or nested objects since the only usage is for email templates and
13051313 // object passed for events
13061314 $ mergedCustomerData = $ this ->customerRegistry ->retrieveSecureData ($ customer ->getId ());
1307- $ customerData = $ this -> dataProcessor
1308- ->buildOutputDataArray ($ customer , \Magento \Customer \Api \Data \CustomerInterface::class);
1315+ $ customerData =
1316+ $ this -> dataProcessor ->buildOutputDataArray ($ customer , \Magento \Customer \Api \Data \CustomerInterface::class);
13091317 $ mergedCustomerData ->addData ($ customerData );
13101318 $ mergedCustomerData ->setData ('name ' , $ this ->customerViewHelper ->getCustomerName ($ customer ));
13111319 return $ mergedCustomerData ;
0 commit comments