8
8
namespace Magento \Customer \Controller \Account ;
9
9
10
10
use Magento \Customer \Api \Data \CustomerInterface ;
11
+ use Magento \Customer \Api \SessionCleanerInterface ;
11
12
use Magento \Customer \Model \AddressRegistry ;
12
13
use Magento \Framework \App \Action \HttpPostActionInterface as HttpPostActionInterface ;
13
14
use Magento \Customer \Model \AuthenticationInterface ;
27
28
use Magento \Framework \Escaper ;
28
29
use Magento \Framework \Exception \InputException ;
29
30
use Magento \Framework \Exception \InvalidEmailOrPasswordException ;
31
+ use Magento \Framework \Exception \LocalizedException ;
30
32
use Magento \Framework \Exception \NoSuchEntityException ;
31
33
use Magento \Framework \Exception \State \UserLockedException ;
32
34
use Magento \Customer \Controller \AbstractAccount ;
33
35
use Magento \Framework \Phrase ;
34
36
35
37
/**
36
- * Class EditPost
38
+ * Customer edit page.
39
+ *
37
40
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
38
41
*/
39
42
class EditPost extends AbstractAccount implements CsrfAwareActionInterface, HttpPostActionInterface
@@ -69,7 +72,7 @@ class EditPost extends AbstractAccount implements CsrfAwareActionInterface, Http
69
72
protected $ session ;
70
73
71
74
/**
72
- * @var \Magento\Customer\Model\ EmailNotificationInterface
75
+ * @var EmailNotificationInterface
73
76
*/
74
77
private $ emailNotification ;
75
78
@@ -93,6 +96,11 @@ class EditPost extends AbstractAccount implements CsrfAwareActionInterface, Http
93
96
*/
94
97
private $ addressRegistry ;
95
98
99
+ /**
100
+ * @var SessionCleanerInterface|null
101
+ */
102
+ private $ sessionCleaner ;
103
+
96
104
/**
97
105
* @param Context $context
98
106
* @param Session $customerSession
@@ -102,6 +110,7 @@ class EditPost extends AbstractAccount implements CsrfAwareActionInterface, Http
102
110
* @param CustomerExtractor $customerExtractor
103
111
* @param Escaper|null $escaper
104
112
* @param AddressRegistry|null $addressRegistry
113
+ * @param SessionCleanerInterface|null $sessionCleaner
105
114
*/
106
115
public function __construct (
107
116
Context $ context ,
@@ -111,7 +120,8 @@ public function __construct(
111
120
Validator $ formKeyValidator ,
112
121
CustomerExtractor $ customerExtractor ,
113
122
?Escaper $ escaper = null ,
114
- AddressRegistry $ addressRegistry = null
123
+ AddressRegistry $ addressRegistry = null ,
124
+ ?SessionCleanerInterface $ sessionCleaner = null
115
125
) {
116
126
parent ::__construct ($ context );
117
127
$ this ->session = $ customerSession ;
@@ -121,6 +131,7 @@ public function __construct(
121
131
$ this ->customerExtractor = $ customerExtractor ;
122
132
$ this ->escaper = $ escaper ?: ObjectManager::getInstance ()->get (Escaper::class);
123
133
$ this ->addressRegistry = $ addressRegistry ?: ObjectManager::getInstance ()->get (AddressRegistry::class);
134
+ $ this ->sessionCleaner = $ sessionCleaner ?: ObjectManager::getInstance ()->get (SessionCleanerInterface::class);
124
135
}
125
136
126
137
/**
@@ -132,9 +143,7 @@ private function getAuthentication()
132
143
{
133
144
134
145
if (!($ this ->authentication instanceof AuthenticationInterface)) {
135
- return ObjectManager::getInstance ()->get (
136
- \Magento \Customer \Model \AuthenticationInterface::class
137
- );
146
+ return ObjectManager::getInstance ()->get (AuthenticationInterface::class);
138
147
} else {
139
148
return $ this ->authentication ;
140
149
}
@@ -149,9 +158,7 @@ private function getAuthentication()
149
158
private function getEmailNotification ()
150
159
{
151
160
if (!($ this ->emailNotification instanceof EmailNotificationInterface)) {
152
- return ObjectManager::getInstance ()->get (
153
- EmailNotificationInterface::class
154
- );
161
+ return ObjectManager::getInstance ()->get (EmailNotificationInterface::class);
155
162
} else {
156
163
return $ this ->emailNotification ;
157
164
}
@@ -160,9 +167,8 @@ private function getEmailNotification()
160
167
/**
161
168
* @inheritDoc
162
169
*/
163
- public function createCsrfValidationException (
164
- RequestInterface $ request
165
- ): ?InvalidRequestException {
170
+ public function createCsrfValidationException (RequestInterface $ request ): ?InvalidRequestException
171
+ {
166
172
/** @var Redirect $resultRedirect */
167
173
$ resultRedirect = $ this ->resultRedirectFactory ->create ();
168
174
$ resultRedirect ->setPath ('*/*/edit ' );
@@ -184,11 +190,11 @@ public function validateForCsrf(RequestInterface $request): ?bool
184
190
/**
185
191
* Change customer email or password action
186
192
*
187
- * @return \Magento\Framework\Controller\Result\ Redirect
193
+ * @return Redirect
188
194
*/
189
195
public function execute ()
190
196
{
191
- /** @var \Magento\Framework\Controller\Result\ Redirect $resultRedirect */
197
+ /** @var Redirect $resultRedirect */
192
198
$ resultRedirect = $ this ->resultRedirectFactory ->create ();
193
199
$ validFormKey = $ this ->formKeyValidator ->validate ($ this ->getRequest ());
194
200
@@ -217,6 +223,7 @@ public function execute()
217
223
);
218
224
$ this ->dispatchSuccessEvent ($ customerCandidateDataObject );
219
225
$ this ->messageManager ->addSuccessMessage (__ ('You saved the account information. ' ));
226
+
220
227
return $ resultRedirect ->setPath ('customer/account ' );
221
228
} catch (InvalidEmailOrPasswordException $ e ) {
222
229
$ this ->messageManager ->addErrorMessage ($ this ->escaper ->escapeHtml ($ e ->getMessage ()));
@@ -228,13 +235,14 @@ public function execute()
228
235
$ this ->session ->logout ();
229
236
$ this ->session ->start ();
230
237
$ this ->messageManager ->addErrorMessage ($ message );
238
+
231
239
return $ resultRedirect ->setPath ('customer/account/login ' );
232
240
} catch (InputException $ e ) {
233
241
$ this ->messageManager ->addErrorMessage ($ this ->escaper ->escapeHtml ($ e ->getMessage ()));
234
242
foreach ($ e ->getErrors () as $ error ) {
235
243
$ this ->messageManager ->addErrorMessage ($ this ->escaper ->escapeHtml ($ error ->getMessage ()));
236
244
}
237
- } catch (\ Magento \ Framework \ Exception \ LocalizedException $ e ) {
245
+ } catch (LocalizedException $ e ) {
238
246
$ this ->messageManager ->addErrorMessage ($ e ->getMessage ());
239
247
} catch (\Exception $ e ) {
240
248
$ this ->messageManager ->addException ($ e , __ ('We can \'t save the customer. ' ));
@@ -246,16 +254,17 @@ public function execute()
246
254
/** @var Redirect $resultRedirect */
247
255
$ resultRedirect = $ this ->resultRedirectFactory ->create ();
248
256
$ resultRedirect ->setPath ('*/*/edit ' );
257
+
249
258
return $ resultRedirect ;
250
259
}
251
260
252
261
/**
253
262
* Account editing action completed successfully event
254
263
*
255
- * @param \Magento\Customer\Api\Data\ CustomerInterface $customerCandidateDataObject
264
+ * @param CustomerInterface $customerCandidateDataObject
256
265
* @return void
257
266
*/
258
- private function dispatchSuccessEvent (\ Magento \ Customer \ Api \ Data \ CustomerInterface $ customerCandidateDataObject )
267
+ private function dispatchSuccessEvent (CustomerInterface $ customerCandidateDataObject )
259
268
{
260
269
$ this ->_eventManager ->dispatch (
261
270
'customer_account_edited ' ,
@@ -268,7 +277,7 @@ private function dispatchSuccessEvent(\Magento\Customer\Api\Data\CustomerInterfa
268
277
*
269
278
* @param int $customerId
270
279
*
271
- * @return \Magento\Customer\Api\Data\ CustomerInterface
280
+ * @return CustomerInterface
272
281
*/
273
282
private function getCustomerDataObject ($ customerId )
274
283
{
@@ -278,13 +287,13 @@ private function getCustomerDataObject($customerId)
278
287
/**
279
288
* Create Data Transfer Object of customer candidate
280
289
*
281
- * @param \Magento\Framework\App\ RequestInterface $inputData
282
- * @param \Magento\Customer\Api\Data\ CustomerInterface $currentCustomerData
283
- * @return \Magento\Customer\Api\Data\ CustomerInterface
290
+ * @param RequestInterface $inputData
291
+ * @param CustomerInterface $currentCustomerData
292
+ * @return CustomerInterface
284
293
*/
285
294
private function populateNewCustomerDataObject (
286
- \ Magento \ Framework \ App \ RequestInterface $ inputData ,
287
- \ Magento \ Customer \ Api \ Data \ CustomerInterface $ currentCustomerData
295
+ RequestInterface $ inputData ,
296
+ CustomerInterface $ currentCustomerData
288
297
) {
289
298
$ attributeValues = $ this ->getCustomerMapper ()->toFlatArray ($ currentCustomerData );
290
299
$ customerDto = $ this ->customerExtractor ->extract (
@@ -330,12 +339,12 @@ protected function changeCustomerPassword($email)
330
339
/**
331
340
* Process change email request
332
341
*
333
- * @param \Magento\Customer\Api\Data\ CustomerInterface $currentCustomerDataObject
342
+ * @param CustomerInterface $currentCustomerDataObject
334
343
* @return void
335
344
* @throws InvalidEmailOrPasswordException
336
345
* @throws UserLockedException
337
346
*/
338
- private function processChangeEmailRequest (\ Magento \ Customer \ Api \ Data \ CustomerInterface $ currentCustomerDataObject )
347
+ private function processChangeEmailRequest (CustomerInterface $ currentCustomerDataObject )
339
348
{
340
349
if ($ this ->getRequest ()->getParam ('change_email ' )) {
341
350
// authenticate user for changing email
@@ -344,6 +353,7 @@ private function processChangeEmailRequest(\Magento\Customer\Api\Data\CustomerIn
344
353
$ currentCustomerDataObject ->getId (),
345
354
$ this ->getRequest ()->getPost ('current_password ' )
346
355
);
356
+ $ this ->sessionCleaner ->clearFor ($ currentCustomerDataObject ->getId ());
347
357
} catch (InvalidEmailOrPasswordException $ e ) {
348
358
throw new InvalidEmailOrPasswordException (
349
359
__ ("The password doesn't match this account. Verify the password and try again. " )
@@ -362,7 +372,7 @@ private function processChangeEmailRequest(\Magento\Customer\Api\Data\CustomerIn
362
372
private function getCustomerMapper ()
363
373
{
364
374
if ($ this ->customerMapper === null ) {
365
- $ this ->customerMapper = ObjectManager::getInstance ()->get (\ Magento \ Customer \ Model \ Customer \ Mapper::class);
375
+ $ this ->customerMapper = ObjectManager::getInstance ()->get (Mapper::class);
366
376
}
367
377
return $ this ->customerMapper ;
368
378
}
0 commit comments