1
1
<?php
2
2
/**
3
- *
4
3
* Copyright © Magento, Inc. All rights reserved.
5
4
* See COPYING.txt for license details.
6
5
*/
6
+ declare (strict_types=1 );
7
+
7
8
namespace Magento \Customer \Controller \Account ;
8
9
9
10
use Magento \Customer \Api \AccountManagementInterface ;
15
16
use Magento \Framework \App \Action \Context ;
16
17
use Magento \Framework \App \Action \HttpGetActionInterface as HttpGetActionInterface ;
17
18
use Magento \Framework \App \Config \ScopeConfigInterface ;
19
+ use Magento \Framework \App \ObjectManager ;
18
20
use Magento \Framework \Controller \ResultFactory ;
21
+ use Magento \Framework \Exception \NoSuchEntityException ;
22
+ use Magento \Framework \Phrase ;
19
23
use Magento \Framework \UrlFactory ;
20
24
use Magento \Framework \Exception \StateException ;
21
25
use Magento \Store \Model \ScopeInterface ;
22
26
use Magento \Store \Model \StoreManagerInterface ;
27
+ use Magento \Customer \Model \Logger as CustomerLogger ;
23
28
24
29
/**
25
30
* Class Confirm
@@ -75,6 +80,11 @@ class Confirm extends AbstractAccount implements HttpGetActionInterface
75
80
*/
76
81
private $ cookieMetadataManager ;
77
82
83
+ /**
84
+ * @var CustomerLogger
85
+ */
86
+ private CustomerLogger $ customerLogger ;
87
+
78
88
/**
79
89
* @param Context $context
80
90
* @param Session $customerSession
@@ -84,6 +94,7 @@ class Confirm extends AbstractAccount implements HttpGetActionInterface
84
94
* @param CustomerRepositoryInterface $customerRepository
85
95
* @param Address $addressHelper
86
96
* @param UrlFactory $urlFactory
97
+ * @param CustomerLogger|null $customerLogger
87
98
*/
88
99
public function __construct (
89
100
Context $ context ,
@@ -93,7 +104,8 @@ public function __construct(
93
104
AccountManagementInterface $ customerAccountManagement ,
94
105
CustomerRepositoryInterface $ customerRepository ,
95
106
Address $ addressHelper ,
96
- UrlFactory $ urlFactory
107
+ UrlFactory $ urlFactory ,
108
+ ?CustomerLogger $ customerLogger = null
97
109
) {
98
110
$ this ->session = $ customerSession ;
99
111
$ this ->scopeConfig = $ scopeConfig ;
@@ -102,13 +114,13 @@ public function __construct(
102
114
$ this ->customerRepository = $ customerRepository ;
103
115
$ this ->addressHelper = $ addressHelper ;
104
116
$ this ->urlModel = $ urlFactory ->create ();
117
+ $ this ->customerLogger = $ customerLogger ?? ObjectManager::getInstance ()->get (CustomerLogger::class);
105
118
parent ::__construct ($ context );
106
119
}
107
120
108
121
/**
109
122
* Retrieve cookie manager
110
123
*
111
- * @deprecated 101.0.0
112
124
* @return \Magento\Framework\Stdlib\Cookie\PhpCookieManager
113
125
*/
114
126
private function getCookieManager ()
@@ -124,7 +136,6 @@ private function getCookieManager()
124
136
/**
125
137
* Retrieve cookie metadata factory
126
138
*
127
- * @deprecated 101.0.0
128
139
* @return \Magento\Framework\Stdlib\Cookie\CookieMetadataFactory
129
140
*/
130
141
private function getCookieMetadataFactory ()
@@ -152,7 +163,7 @@ public function execute()
152
163
return $ resultRedirect ;
153
164
}
154
165
155
- $ customerId = $ this ->getRequest ()-> getParam ( ' id ' , false );
166
+ $ customerId = $ this ->getCustomerId ( );
156
167
$ key = $ this ->getRequest ()->getParam ('key ' , false );
157
168
if (empty ($ customerId ) || empty ($ key )) {
158
169
$ this ->messageManager ->addErrorMessage (__ ('Bad request. ' ));
@@ -164,13 +175,19 @@ public function execute()
164
175
// log in and send greeting email
165
176
$ customerEmail = $ this ->customerRepository ->getById ($ customerId )->getEmail ();
166
177
$ customer = $ this ->customerAccountManagement ->activate ($ customerEmail , $ key );
178
+ $ successMessage = $ this ->getSuccessMessage ();
167
179
$ this ->session ->setCustomerDataAsLoggedIn ($ customer );
180
+
168
181
if ($ this ->getCookieManager ()->getCookie ('mage-cache-sessid ' )) {
169
182
$ metadata = $ this ->getCookieMetadataFactory ()->createCookieMetadata ();
170
183
$ metadata ->setPath ('/ ' );
171
184
$ this ->getCookieManager ()->deleteCookie ('mage-cache-sessid ' , $ metadata );
172
185
}
173
- $ this ->messageManager ->addSuccess ($ this ->getSuccessMessage ());
186
+
187
+ if ($ successMessage ) {
188
+ $ this ->messageManager ->addSuccess ($ successMessage );
189
+ }
190
+
174
191
$ resultRedirect ->setUrl ($ this ->getSuccessRedirect ());
175
192
return $ resultRedirect ;
176
193
} catch (StateException $ e ) {
@@ -183,33 +200,41 @@ public function execute()
183
200
return $ resultRedirect ->setUrl ($ this ->_redirect ->error ($ url ));
184
201
}
185
202
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
+
186
213
/**
187
214
* Retrieve success message
188
215
*
189
- * @return string
216
+ * @return Phrase|null
217
+ * @throws NoSuchEntityException
190
218
*/
191
219
protected function getSuccessMessage ()
192
220
{
193
221
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
+ );
211
230
}
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 ());
213
238
}
214
239
215
240
/**
0 commit comments