11<?php
22/**
3- *
43 * Copyright © Magento, Inc. All rights reserved.
54 * See COPYING.txt for license details.
65 */
6+ declare (strict_types=1 );
7+
78namespace Magento \Customer \Controller \Account ;
89
910use Magento \Customer \Api \AccountManagementInterface ;
1516use Magento \Framework \App \Action \Context ;
1617use Magento \Framework \App \Action \HttpGetActionInterface as HttpGetActionInterface ;
1718use Magento \Framework \App \Config \ScopeConfigInterface ;
19+ use Magento \Framework \App \ObjectManager ;
1820use Magento \Framework \Controller \ResultFactory ;
21+ use Magento \Framework \Exception \NoSuchEntityException ;
22+ use Magento \Framework \Phrase ;
1923use Magento \Framework \UrlFactory ;
2024use Magento \Framework \Exception \StateException ;
2125use Magento \Store \Model \ScopeInterface ;
2226use Magento \Store \Model \StoreManagerInterface ;
27+ use Magento \Customer \Model \Logger as CustomerLogger ;
2328
2429/**
2530 * Class Confirm
@@ -75,6 +80,11 @@ class Confirm extends AbstractAccount implements HttpGetActionInterface
7580 */
7681 private $ cookieMetadataManager ;
7782
83+ /**
84+ * @var CustomerLogger
85+ */
86+ private CustomerLogger $ customerLogger ;
87+
7888 /**
7989 * @param Context $context
8090 * @param Session $customerSession
@@ -84,6 +94,7 @@ class Confirm extends AbstractAccount implements HttpGetActionInterface
8494 * @param CustomerRepositoryInterface $customerRepository
8595 * @param Address $addressHelper
8696 * @param UrlFactory $urlFactory
97+ * @param CustomerLogger|null $customerLogger
8798 */
8899 public function __construct (
89100 Context $ context ,
@@ -93,7 +104,8 @@ public function __construct(
93104 AccountManagementInterface $ customerAccountManagement ,
94105 CustomerRepositoryInterface $ customerRepository ,
95106 Address $ addressHelper ,
96- UrlFactory $ urlFactory
107+ UrlFactory $ urlFactory ,
108+ ?CustomerLogger $ customerLogger = null
97109 ) {
98110 $ this ->session = $ customerSession ;
99111 $ this ->scopeConfig = $ scopeConfig ;
@@ -102,13 +114,13 @@ public function __construct(
102114 $ this ->customerRepository = $ customerRepository ;
103115 $ this ->addressHelper = $ addressHelper ;
104116 $ this ->urlModel = $ urlFactory ->create ();
117+ $ this ->customerLogger = $ customerLogger ?? ObjectManager::getInstance ()->get (CustomerLogger::class);
105118 parent ::__construct ($ context );
106119 }
107120
108121 /**
109122 * Retrieve cookie manager
110123 *
111- * @deprecated 101.0.0
112124 * @return \Magento\Framework\Stdlib\Cookie\PhpCookieManager
113125 */
114126 private function getCookieManager ()
@@ -124,7 +136,6 @@ private function getCookieManager()
124136 /**
125137 * Retrieve cookie metadata factory
126138 *
127- * @deprecated 101.0.0
128139 * @return \Magento\Framework\Stdlib\Cookie\CookieMetadataFactory
129140 */
130141 private function getCookieMetadataFactory ()
@@ -152,7 +163,7 @@ public function execute()
152163 return $ resultRedirect ;
153164 }
154165
155- $ customerId = $ this ->getRequest ()-> getParam ( ' id ' , false );
166+ $ customerId = $ this ->getCustomerId ( );
156167 $ key = $ this ->getRequest ()->getParam ('key ' , false );
157168 if (empty ($ customerId ) || empty ($ key )) {
158169 $ this ->messageManager ->addErrorMessage (__ ('Bad request. ' ));
@@ -164,13 +175,19 @@ public function execute()
164175 // log in and send greeting email
165176 $ customerEmail = $ this ->customerRepository ->getById ($ customerId )->getEmail ();
166177 $ customer = $ this ->customerAccountManagement ->activate ($ customerEmail , $ key );
178+ $ successMessage = $ this ->getSuccessMessage ();
167179 $ this ->session ->setCustomerDataAsLoggedIn ($ customer );
180+
168181 if ($ this ->getCookieManager ()->getCookie ('mage-cache-sessid ' )) {
169182 $ metadata = $ this ->getCookieMetadataFactory ()->createCookieMetadata ();
170183 $ metadata ->setPath ('/ ' );
171184 $ this ->getCookieManager ()->deleteCookie ('mage-cache-sessid ' , $ metadata );
172185 }
173- $ this ->messageManager ->addSuccess ($ this ->getSuccessMessage ());
186+
187+ if ($ successMessage ) {
188+ $ this ->messageManager ->addSuccess ($ successMessage );
189+ }
190+
174191 $ resultRedirect ->setUrl ($ this ->getSuccessRedirect ());
175192 return $ resultRedirect ;
176193 } catch (StateException $ e ) {
@@ -183,33 +200,41 @@ public function execute()
183200 return $ resultRedirect ->setUrl ($ this ->_redirect ->error ($ url ));
184201 }
185202
203+ /**
204+ * Returns customer id from request
205+ *
206+ * @return int
207+ */
208+ private function getCustomerId (): int
209+ {
210+ return (int )$ this ->getRequest ()->getParam ('id ' , 0 );
211+ }
212+
186213 /**
187214 * Retrieve success message
188215 *
189- * @return string
216+ * @return Phrase|null
217+ * @throws NoSuchEntityException
190218 */
191219 protected function getSuccessMessage ()
192220 {
193221 if ($ this ->addressHelper ->isVatValidationEnabled ()) {
194- if ($ this ->addressHelper ->getTaxCalculationAddressType () == Address::TYPE_SHIPPING ) {
195- // @codingStandardsIgnoreStart
196- $ message = __ (
197- 'If you are a registered VAT customer, please click <a href="%1">here</a> to enter your shipping address for proper VAT calculation. ' ,
198- $ this ->urlModel ->getUrl ('customer/address/edit ' )
199- );
200- // @codingStandardsIgnoreEnd
201- } else {
202- // @codingStandardsIgnoreStart
203- $ message = __ (
204- 'If you are a registered VAT customer, please click <a href="%1">here</a> to enter your billing address for proper VAT calculation. ' ,
205- $ this ->urlModel ->getUrl ('customer/address/edit ' )
206- );
207- // @codingStandardsIgnoreEnd
208- }
209- } else {
210- $ message = __ ('Thank you for registering with %1. ' , $ this ->storeManager ->getStore ()->getFrontendName ());
222+ return __ (
223+ $ this ->addressHelper ->getTaxCalculationAddressType () == Address::TYPE_SHIPPING
224+ ? 'If you are a registered VAT customer, please click <a href="%1">here</a> to enter your '
225+ .'shipping address for proper VAT calculation. '
226+ :'If you are a registered VAT customer, please click <a href="%1">here</a> to enter your '
227+ .'billing address for proper VAT calculation. ' ,
228+ $ this ->urlModel ->getUrl ('customer/address/edit ' )
229+ );
211230 }
212- return $ message ;
231+
232+ $ customerId = $ this ->getCustomerId ();
233+ if ($ customerId && $ this ->customerLogger ->get ($ customerId )->getLastLoginAt ()) {
234+ return null ;
235+ }
236+
237+ return __ ('Thank you for registering with %1. ' , $ this ->storeManager ->getStore ()->getFrontendName ());
213238 }
214239
215240 /**
0 commit comments