44 * See COPYING.txt for license details.
55 */
66
7- // @codingStandardsIgnoreFile
8-
97namespace Magento \Customer \Model ;
108
119use Magento \Customer \Api \AccountManagementInterface ;
2018use Magento \Customer \Model \Customer as CustomerModel ;
2119use Magento \Customer \Model \Metadata \Validator ;
2220use Magento \Framework \Api \ExtensibleDataObjectConverter ;
21+ use Magento \Framework \App \Area ;
2322use Magento \Framework \App \Config \ScopeConfigInterface ;
2423use Magento \Framework \Encryption \EncryptorInterface as Encryptor ;
2524use Magento \Framework \Encryption \Helper \Security ;
3534use Magento \Framework \Exception \State \InvalidTransitionException ;
3635use Magento \Framework \DataObjectFactory as ObjectFactory ;
3736use Magento \Framework \Registry ;
37+ use Magento \Store \Model \ScopeInterface ;
3838use Psr \Log \LoggerInterface as PsrLogger ;
3939use Magento \Framework \Exception \MailException ;
4040use Magento \Framework \Mail \Template \TransportBuilder ;
@@ -394,7 +394,7 @@ public function validateResetPasswordLinkToken($customerId, $resetPasswordLinkTo
394394 */
395395 public function initiatePasswordReset ($ email , $ template , $ websiteId = null )
396396 {
397- if (is_null ( $ websiteId) ) {
397+ if ($ websiteId === null ) {
398398 $ websiteId = $ this ->storeManager ->getStore ()->getWebsiteId ();
399399 }
400400 // load customer by email
@@ -464,12 +464,9 @@ public function getConfirmationStatus($customerId)
464464 /**
465465 * {@inheritdoc}
466466 */
467- public function createAccount (
468- CustomerInterface $ customer ,
469- $ password = null ,
470- $ redirectUrl = ''
471- ) {
472- if (!is_null ($ password )) {
467+ public function createAccount (CustomerInterface $ customer , $ password = null , $ redirectUrl = '' )
468+ {
469+ if ($ password !== null ) {
473470 $ this ->checkPasswordStrength ($ password );
474471 } else {
475472 $ password = $ this ->mathRandom ->getRandomString (self ::MIN_PASSWORD_LENGTH );
@@ -483,11 +480,8 @@ public function createAccount(
483480 * @SuppressWarnings(PHPMD.CyclomaticComplexity)
484481 * @SuppressWarnings(PHPMD.NPathComplexity)
485482 */
486- public function createAccountWithPasswordHash (
487- CustomerInterface $ customer ,
488- $ hash ,
489- $ redirectUrl = ''
490- ) {
483+ public function createAccountWithPasswordHash (CustomerInterface $ customer , $ hash , $ redirectUrl = '' )
484+ {
491485 // This logic allows an existing customer to be added to a different store. No new account is created.
492486 // The plan is to move this logic into a new method called something like 'registerAccountWithStore'
493487 if ($ customer ->getId ()) {
@@ -568,20 +562,11 @@ protected function sendEmailConfirmation(CustomerInterface $customer, $redirectU
568562 {
569563 try {
570564 if ($ this ->isConfirmationRequired ($ customer )) {
571- $ this ->sendNewAccountEmail (
572- $ customer ,
573- self ::NEW_ACCOUNT_EMAIL_CONFIRMATION ,
574- $ redirectUrl ,
575- $ customer ->getStoreId ()
576- );
565+ $ templateType = self ::NEW_ACCOUNT_EMAIL_CONFIRMATION ;
577566 } else {
578- $ this ->sendNewAccountEmail (
579- $ customer ,
580- self ::NEW_ACCOUNT_EMAIL_REGISTERED ,
581- $ redirectUrl ,
582- $ customer ->getStoreId ()
583- );
567+ $ templateType = self ::NEW_ACCOUNT_EMAIL_REGISTERED ;
584568 }
569+ $ this ->sendNewAccountEmail ($ customer , $ templateType , $ redirectUrl , $ customer ->getStoreId ());
585570 } catch (MailException $ e ) {
586571 // If we are not able to send a new account email, this should be ignored
587572 $ this ->logger ->critical ($ e );
@@ -683,13 +668,11 @@ protected function createPasswordHash($password)
683668 /**
684669 * {@inheritdoc}
685670 */
686- public function validate (\ Magento \ Customer \ Api \ Data \ CustomerInterface $ customer )
671+ public function validate (CustomerInterface $ customer )
687672 {
688- $ customerErrors = $ this ->validator ->validateData (
689- $ this ->extensibleDataObjectConverter ->toFlatArray ($ customer , [], '\Magento\Customer\Api\Data\CustomerInterface ' ),
690- [],
691- 'customer '
692- );
673+ $ customerData = $ this ->extensibleDataObjectConverter
674+ ->toFlatArray ($ customer , [], '\Magento\Customer\Api\Data\CustomerInterface ' );
675+ $ customerErrors = $ this ->validator ->validateData ($ customerData , [], 'customer ' );
693676
694677 $ validationResults = $ this ->validationResultsDataFactory ->create ();
695678 if ($ customerErrors !== true ) {
@@ -718,7 +701,7 @@ public function validate(\Magento\Customer\Api\Data\CustomerInterface $customer)
718701 public function isEmailAvailable ($ customerEmail , $ websiteId = null )
719702 {
720703 try {
721- if (is_null ( $ websiteId) ) {
704+ if ($ websiteId === null ) {
722705 $ websiteId = $ this ->storeManager ->getStore ()->getWebsiteId ();
723706 }
724707 $ this ->customerRepository ->get ($ customerEmail , $ websiteId );
@@ -786,7 +769,7 @@ private function validateResetPasswordToken($customerId, $resetPasswordLinkToken
786769 * @param int $customerId
787770 * @return bool
788771 * @throws \Magento\Framework\Exception\NoSuchEntityException If group is not found
789- * @throws \Magento\Framework\Exception\ LocalizedException
772+ * @throws LocalizedException
790773 */
791774 public function isReadonly ($ customerId )
792775 {
@@ -803,7 +786,7 @@ public function isReadonly($customerId)
803786 * @param string $storeId
804787 * @param string $sendemailStoreId
805788 * @return $this
806- * @throws \Magento\Framework\Exception\ LocalizedException
789+ * @throws LocalizedException
807790 */
808791 protected function sendNewAccountEmail (
809792 $ customer ,
@@ -815,9 +798,7 @@ protected function sendNewAccountEmail(
815798 $ types = $ this ->getTemplateTypes ();
816799
817800 if (!isset ($ types [$ type ])) {
818- throw new \Magento \Framework \Exception \LocalizedException (
819- __ ('Please correct the transactional account email type. ' )
820- );
801+ throw new LocalizedException (__ ('Please correct the transactional account email type. ' ));
821802 }
822803
823804 if (!$ storeId ) {
@@ -853,28 +834,14 @@ protected function sendPasswordResetNotificationEmail($customer)
853834 }
854835
855836 $ customerEmailData = $ this ->getFullCustomerObject ($ customer );
856- /** @var \Magento\Framework\Mail\TransportInterface $transport */
857- $ transport = $ this ->transportBuilder ->setTemplateIdentifier (
858- $ this ->scopeConfig ->getValue (
859- self ::XML_PATH_RESET_PASSWORD_TEMPLATE ,
860- \Magento \Store \Model \ScopeInterface::SCOPE_STORE ,
861- $ storeId
862- )
863- )->setTemplateOptions (
864- ['area ' => \Magento \Framework \App \Area::AREA_FRONTEND , 'store ' => $ storeId ]
865- )->setTemplateVars (
866- ['customer ' => $ customerEmailData , 'store ' => $ this ->storeManager ->getStore ($ storeId )]
867- )->setFrom (
868- $ this ->scopeConfig ->getValue (
869- self ::XML_PATH_FORGOT_EMAIL_IDENTITY ,
870- \Magento \Store \Model \ScopeInterface::SCOPE_STORE ,
871- $ storeId
872- )
873- )->addTo (
874- $ customer ->getEmail (),
875- $ this ->customerViewHelper ->getCustomerName ($ customer )
876- )->getTransport ();
877- $ transport ->sendMessage ();
837+
838+ $ this ->sendEmailTemplate (
839+ $ customer ,
840+ self ::XML_PATH_RESET_PASSWORD_TEMPLATE ,
841+ self ::XML_PATH_FORGOT_EMAIL_IDENTITY ,
842+ ['customer ' => $ customerEmailData , 'store ' => $ this ->storeManager ->getStore ($ storeId )],
843+ $ storeId
844+ );
878845
879846 return $ this ;
880847 }
@@ -926,19 +893,14 @@ protected function getTemplateTypes()
926893 */
927894 protected function sendEmailTemplate ($ customer , $ template , $ sender , $ templateParams = [], $ storeId = null )
928895 {
929- /** @var \Magento\Framework\Mail\TransportInterface $transport */
930- $ transport = $ this ->transportBuilder ->setTemplateIdentifier (
931- $ this ->scopeConfig ->getValue ($ template , \Magento \Store \Model \ScopeInterface::SCOPE_STORE , $ storeId )
932- )->setTemplateOptions (
933- ['area ' => \Magento \Framework \App \Area::AREA_FRONTEND , 'store ' => $ storeId ]
934- )->setTemplateVars (
935- $ templateParams
936- )->setFrom (
937- $ this ->scopeConfig ->getValue ($ sender , \Magento \Store \Model \ScopeInterface::SCOPE_STORE , $ storeId )
938- )->addTo (
939- $ customer ->getEmail (),
940- $ this ->customerViewHelper ->getCustomerName ($ customer )
941- )->getTransport ();
896+ $ templateId = $ this ->scopeConfig ->getValue ($ template , ScopeInterface::SCOPE_STORE , $ storeId );
897+ $ transport = $ this ->transportBuilder ->setTemplateIdentifier ($ templateId )
898+ ->setTemplateOptions (['area ' => Area::AREA_FRONTEND , 'store ' => $ storeId ])
899+ ->setTemplateVars ($ templateParams )
900+ ->setFrom ($ this ->scopeConfig ->getValue ($ sender , ScopeInterface::SCOPE_STORE , $ storeId ))
901+ ->addTo ($ customer ->getEmail (), $ this ->customerViewHelper ->getCustomerName ($ customer ))
902+ ->getTransport ();
903+
942904 $ transport ->sendMessage ();
943905
944906 return $ this ;
@@ -957,11 +919,7 @@ protected function isConfirmationRequired($customer)
957919 }
958920 $ storeId = $ customer ->getStoreId () ? $ customer ->getStoreId () : null ;
959921
960- return (bool )$ this ->scopeConfig ->getValue (
961- self ::XML_PATH_IS_CONFIRM ,
962- \Magento \Store \Model \ScopeInterface::SCOPE_STORE ,
963- $ storeId
964- );
922+ return (bool )$ this ->scopeConfig ->getValue (self ::XML_PATH_IS_CONFIRM , ScopeInterface::SCOPE_STORE , $ storeId );
965923 }
966924
967925 /**
@@ -1039,9 +997,7 @@ public function changeResetPasswordLinkToken($customer, $passwordLinkToken)
1039997 if (is_string ($ passwordLinkToken ) && !empty ($ passwordLinkToken )) {
1040998 $ customerSecure = $ this ->customerRegistry ->retrieveSecureData ($ customer ->getId ());
1041999 $ customerSecure ->setRpToken ($ passwordLinkToken );
1042- $ customerSecure ->setRpTokenCreatedAt (
1043- (new \DateTime ())->format (\Magento \Framework \Stdlib \DateTime::DATETIME_PHP_FORMAT )
1044- );
1000+ $ customerSecure ->setRpTokenCreatedAt ((new \DateTime ())->format (DateTime::DATETIME_PHP_FORMAT ));
10451001 $ this ->customerRepository ->save ($ customer );
10461002 }
10471003 return true ;
0 commit comments