13
13
use Magento \Customer \Api \Data \AddressInterface ;
14
14
use Magento \Customer \Api \Data \CustomerInterface ;
15
15
use Magento \Customer \Api \Data \ValidationResultsInterfaceFactory ;
16
+ use Magento \Customer \Api \SessionCleanerInterface ;
16
17
use Magento \Customer \Helper \View as CustomerViewHelper ;
17
18
use Magento \Customer \Model \Config \Share as ConfigShare ;
18
19
use Magento \Customer \Model \Customer as CustomerModel ;
@@ -68,104 +69,104 @@ class AccountManagement implements AccountManagementInterface
68
69
/**
69
70
* Configuration paths for create account email template
70
71
*
71
- * @deprecated Get rid of Helpers in Password Security Management
72
- * @see EmailNotification::XML_PATH_REGISTER_EMAIL_TEMPLATE
72
+ * @deprecated get rid of Helpers in Password Security Management.
73
+ * @see \Magento\Customer\Model\ EmailNotification::XML_PATH_REGISTER_EMAIL_TEMPLATE
73
74
*/
74
75
const XML_PATH_REGISTER_EMAIL_TEMPLATE = 'customer/create_account/email_template ' ;
75
76
76
77
/**
77
78
* Configuration paths for register no password email template
78
79
*
79
- * @deprecated Get rid of Helpers in Password Security Management
80
- * @see EmailNotification::XML_PATH_REGISTER_EMAIL_TEMPLATE
80
+ * @deprecated get rid of Helpers in Password Security Management.
81
+ * @see \Magento\Customer\Model\ EmailNotification::XML_PATH_REGISTER_NO_PASSWORD_EMAIL_TEMPLATE
81
82
*/
82
83
const XML_PATH_REGISTER_NO_PASSWORD_EMAIL_TEMPLATE = 'customer/create_account/email_no_password_template ' ;
83
84
84
85
/**
85
86
* Configuration paths for remind email identity
86
87
*
87
- * @deprecated Get rid of Helpers in Password Security Management
88
- * @see EmailNotification::XML_PATH_REGISTER_EMAIL_TEMPLATE
88
+ * @deprecated get rid of Helpers in Password Security Management.
89
+ * @see \Magento\Customer\Model\ EmailNotification::XML_PATH_REGISTER_EMAIL_IDENTITY
89
90
*/
90
91
const XML_PATH_REGISTER_EMAIL_IDENTITY = 'customer/create_account/email_identity ' ;
91
92
92
93
/**
93
94
* Configuration paths for remind email template
94
95
*
95
- * @deprecated Get rid of Helpers in Password Security Management
96
- * @see EmailNotification::XML_PATH_REGISTER_EMAIL_TEMPLATE
96
+ * @deprecated get rid of Helpers in Password Security Management.
97
+ * @see \Magento\Customer\Model\ EmailNotification::XML_PATH_REMIND_EMAIL_TEMPLATE
97
98
*/
98
99
const XML_PATH_REMIND_EMAIL_TEMPLATE = 'customer/password/remind_email_template ' ;
99
100
100
101
/**
101
102
* Configuration paths for forgot email email template
102
103
*
103
- * @deprecated Get rid of Helpers in Password Security Management
104
- * @see EmailNotification::XML_PATH_REGISTER_EMAIL_TEMPLATE
104
+ * @deprecated get rid of Helpers in Password Security Management.
105
+ * @see \Magento\Customer\Model\ EmailNotification::XML_PATH_FORGOT_EMAIL_TEMPLATE
105
106
*/
106
107
const XML_PATH_FORGOT_EMAIL_TEMPLATE = 'customer/password/forgot_email_template ' ;
107
108
108
109
/**
109
110
* Configuration paths for forgot email identity
110
111
*
111
- * @deprecated Get rid of Helpers in Password Security Management
112
- * @see EmailNotification::XML_PATH_REGISTER_EMAIL_TEMPLATE
112
+ * @deprecated get rid of Helpers in Password Security Management.
113
+ * @see \Magento\Customer\Model\ EmailNotification::XML_PATH_FORGOT_EMAIL_IDENTITY
113
114
*/
114
115
const XML_PATH_FORGOT_EMAIL_IDENTITY = 'customer/password/forgot_email_identity ' ;
115
116
116
117
/**
117
118
* Configuration paths for account confirmation required
118
119
*
119
- * @deprecated Get rid of Helpers in Password Security Management
120
+ * @deprecated get rid of Helpers in Password Security Management.
120
121
* @see AccountConfirmation::XML_PATH_IS_CONFIRM
121
122
*/
122
123
const XML_PATH_IS_CONFIRM = 'customer/create_account/confirm ' ;
123
124
124
125
/**
125
126
* Configuration paths for account confirmation email template
126
127
*
127
- * @deprecated Get rid of Helpers in Password Security Management
128
- * @see EmailNotification::XML_PATH_REGISTER_EMAIL_TEMPLATE
128
+ * @deprecated get rid of Helpers in Password Security Management.
129
+ * @see \Magento\Customer\Model\ EmailNotification::XML_PATH_CONFIRM_EMAIL_TEMPLATE
129
130
*/
130
131
const XML_PATH_CONFIRM_EMAIL_TEMPLATE = 'customer/create_account/email_confirmation_template ' ;
131
132
132
133
/**
133
134
* Configuration paths for confirmation confirmed email template
134
135
*
135
- * @deprecated Get rid of Helpers in Password Security Management
136
- * @see EmailNotification::XML_PATH_REGISTER_EMAIL_TEMPLATE
136
+ * @deprecated get rid of Helpers in Password Security Management.
137
+ * @see \Magento\Customer\Model\ EmailNotification::XML_PATH_CONFIRMED_EMAIL_TEMPLATE
137
138
*/
138
139
const XML_PATH_CONFIRMED_EMAIL_TEMPLATE = 'customer/create_account/email_confirmed_template ' ;
139
140
140
141
/**
141
142
* Constants for the type of new account email to be sent
142
143
*
143
- * @deprecated Get rid of Helpers in Password Security Management
144
- * @see EmailNotificationInterface::NEW_ACCOUNT_EMAIL_REGISTERED
144
+ * @deprecated get rid of Helpers in Password Security Management.
145
+ * @see \Magento\Customer\Model\ EmailNotificationInterface::NEW_ACCOUNT_EMAIL_REGISTERED
145
146
*/
146
147
const NEW_ACCOUNT_EMAIL_REGISTERED = 'registered ' ;
147
148
148
149
/**
149
150
* Welcome email, when password setting is required
150
151
*
151
- * @deprecated Get rid of Helpers in Password Security Management
152
- * @see EmailNotificationInterface::NEW_ACCOUNT_EMAIL_REGISTERED
152
+ * @deprecated get rid of Helpers in Password Security Management.
153
+ * @see \Magento\Customer\Model\ EmailNotificationInterface::NEW_ACCOUNT_EMAIL_REGISTERED_NO_PASSWORD
153
154
*/
154
155
const NEW_ACCOUNT_EMAIL_REGISTERED_NO_PASSWORD = 'registered_no_password ' ;
155
156
156
157
/**
157
158
* Welcome email, when confirmation is enabled
158
159
*
159
- * @deprecated Get rid of Helpers in Password Security Management
160
- * @see EmailNotificationInterface::NEW_ACCOUNT_EMAIL_REGISTERED
160
+ * @deprecated get rid of Helpers in Password Security Management.
161
+ * @see \Magento\Customer\Model\ EmailNotificationInterface::NEW_ACCOUNT_EMAIL_CONFIRMATION
161
162
*/
162
163
const NEW_ACCOUNT_EMAIL_CONFIRMATION = 'confirmation ' ;
163
164
164
165
/**
165
166
* Confirmation email, when account is confirmed
166
167
*
167
- * @deprecated Get rid of Helpers in Password Security Management
168
- * @see EmailNotificationInterface::NEW_ACCOUNT_EMAIL_REGISTERED
168
+ * @deprecated get rid of Helpers in Password Security Management.
169
+ * @see \Magento\Customer\Model\ EmailNotificationInterface::NEW_ACCOUNT_EMAIL_CONFIRMED
169
170
*/
170
171
const NEW_ACCOUNT_EMAIL_CONFIRMED = 'confirmed ' ;
171
172
@@ -191,15 +192,16 @@ class AccountManagement implements AccountManagementInterface
191
192
/**
192
193
* Configuration path to customer reset password email template
193
194
*
194
- * @deprecated Get rid of Helpers in Password Security Management
195
- * @see Magento/ Customer/ Model/ EmailNotification::XML_PATH_REGISTER_EMAIL_TEMPLATE
195
+ * @deprecated get rid of Helpers in Password Security Management.
196
+ * @see \ Magento\ Customer\ Model\ EmailNotification::XML_PATH_RESET_PASSWORD_TEMPLATE
196
197
*/
197
198
const XML_PATH_RESET_PASSWORD_TEMPLATE = 'customer/password/reset_password_template ' ;
198
199
199
200
/**
200
201
* Minimum password length
201
202
*
202
- * @deprecated Get rid of Helpers in Password Security Management
203
+ * @deprecated get rid of Helpers in Password Security Management.
204
+ * @see \Magento\Customer\Model\AccountManagement::XML_PATH_MINIMUM_PASSWORD_LENGTH
203
205
*/
204
206
const MIN_PASSWORD_LENGTH = 6 ;
205
207
@@ -283,21 +285,6 @@ class AccountManagement implements AccountManagementInterface
283
285
*/
284
286
private $ transportBuilder ;
285
287
286
- /**
287
- * @var SessionManagerInterface
288
- */
289
- private $ sessionManager ;
290
-
291
- /**
292
- * @var SaveHandlerInterface
293
- */
294
- private $ saveHandler ;
295
-
296
- /**
297
- * @var CollectionFactory
298
- */
299
- private $ visitorCollectionFactory ;
300
-
301
288
/**
302
289
* @var DataObjectProcessor
303
290
*/
@@ -383,6 +370,11 @@ class AccountManagement implements AccountManagementInterface
383
370
*/
384
371
private $ getByToken ;
385
372
373
+ /**
374
+ * @var SessionCleanerInterface
375
+ */
376
+ private $ sessionCleaner ;
377
+
386
378
/**
387
379
* @param CustomerFactory $customerFactory
388
380
* @param ManagerInterface $eventManager
@@ -417,10 +409,12 @@ class AccountManagement implements AccountManagementInterface
417
409
* @param AddressRegistry|null $addressRegistry
418
410
* @param GetCustomerByToken|null $getByToken
419
411
* @param AllowedCountries|null $allowedCountriesReader
412
+ * @param SessionCleanerInterface|null $sessionCleaner
420
413
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
421
414
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
422
415
* @SuppressWarnings(PHPMD.NPathComplexity)
423
416
* @SuppressWarnings(PHPMD.LongVariable)
417
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
424
418
*/
425
419
public function __construct (
426
420
CustomerFactory $ customerFactory ,
@@ -455,7 +449,8 @@ public function __construct(
455
449
SearchCriteriaBuilder $ searchCriteriaBuilder = null ,
456
450
AddressRegistry $ addressRegistry = null ,
457
451
GetCustomerByToken $ getByToken = null ,
458
- AllowedCountries $ allowedCountriesReader = null
452
+ AllowedCountries $ allowedCountriesReader = null ,
453
+ SessionCleanerInterface $ sessionCleaner = null
459
454
) {
460
455
$ this ->customerFactory = $ customerFactory ;
461
456
$ this ->eventManager = $ eventManager ;
@@ -486,12 +481,6 @@ public function __construct(
486
481
$ this ->dateTimeFactory = $ dateTimeFactory ?: $ objectManager ->get (DateTimeFactory::class);
487
482
$ this ->accountConfirmation = $ accountConfirmation ?: $ objectManager
488
483
->get (AccountConfirmation::class);
489
- $ this ->sessionManager = $ sessionManager
490
- ?: $ objectManager ->get (SessionManagerInterface::class);
491
- $ this ->saveHandler = $ saveHandler
492
- ?: $ objectManager ->get (SaveHandlerInterface::class);
493
- $ this ->visitorCollectionFactory = $ visitorCollectionFactory
494
- ?: $ objectManager ->get (CollectionFactory::class);
495
484
$ this ->searchCriteriaBuilder = $ searchCriteriaBuilder
496
485
?: $ objectManager ->get (SearchCriteriaBuilder::class);
497
486
$ this ->addressRegistry = $ addressRegistry
@@ -500,6 +489,7 @@ public function __construct(
500
489
?: $ objectManager ->get (GetCustomerByToken::class);
501
490
$ this ->allowedCountriesReader = $ allowedCountriesReader
502
491
?: $ objectManager ->get (AllowedCountries::class);
492
+ $ this ->sessionCleaner = $ sessionCleaner ?? $ objectManager ->get (SessionCleanerInterface::class);
503
493
}
504
494
505
495
/**
@@ -538,7 +528,10 @@ public function resendConfirmation($email, $websiteId = null, $redirectUrl = '')
538
528
} catch (MailException $ e ) {
539
529
// If we are not able to send a new account email, this should be ignored
540
530
$ this ->logger ->critical ($ e );
531
+
532
+ return false ;
541
533
}
534
+
542
535
return true ;
543
536
}
544
537
@@ -685,16 +678,18 @@ public function initiatePasswordReset($email, $template, $websiteId = null)
685
678
*/
686
679
private function handleUnknownTemplate ($ template )
687
680
{
688
- $ phrase = __ (
689
- 'Invalid value of "%value" provided for the %fieldName field. Possible values: %template1 or %template2. ' ,
690
- [
691
- 'value ' => $ template ,
692
- 'fieldName ' => 'template ' ,
693
- 'template1 ' => AccountManagement::EMAIL_REMINDER ,
694
- 'template2 ' => AccountManagement::EMAIL_RESET
695
- ]
681
+ throw new InputException (
682
+ __ (
683
+ 'Invalid value of "%value" provided for the %fieldName field. '
684
+ . 'Possible values: %template1 or %template2. ' ,
685
+ [
686
+ 'value ' => $ template ,
687
+ 'fieldName ' => 'template ' ,
688
+ 'template1 ' => AccountManagement::EMAIL_REMINDER ,
689
+ 'template2 ' => AccountManagement::EMAIL_RESET
690
+ ]
691
+ )
696
692
);
697
- throw new InputException ($ phrase );
698
693
}
699
694
700
695
/**
@@ -725,7 +720,7 @@ public function resetPassword($email, $resetToken, $newPassword)
725
720
$ customerSecure ->setRpToken (null );
726
721
$ customerSecure ->setRpTokenCreatedAt (null );
727
722
$ customerSecure ->setPasswordHash ($ this ->createPasswordHash ($ newPassword ));
728
- $ this ->destroyCustomerSessions ( $ customer ->getId ());
723
+ $ this ->sessionCleaner -> clearFor (( int ) $ customer ->getId ());
729
724
$ this ->customerRepository ->save ($ customer );
730
725
731
726
return true ;
@@ -872,6 +867,7 @@ public function createAccountWithPasswordHash(CustomerInterface $customer, $hash
872
867
if ($ customer ->getId ()) {
873
868
$ customer = $ this ->customerRepository ->get ($ customer ->getEmail ());
874
869
$ websiteId = $ customer ->getWebsiteId ();
870
+
875
871
if ($ this ->isCustomerInStore ($ websiteId , $ customer ->getStoreId ())) {
876
872
throw new InputException (__ ('This customer already exists in this store. ' ));
877
873
}
@@ -1050,7 +1046,7 @@ private function changePasswordForCustomer($customer, $currentPassword, $newPass
1050
1046
$ customerSecure ->setRpTokenCreatedAt (null );
1051
1047
$ this ->checkPasswordStrength ($ newPassword );
1052
1048
$ customerSecure ->setPasswordHash ($ this ->createPasswordHash ($ newPassword ));
1053
- $ this ->destroyCustomerSessions ( $ customer ->getId ());
1049
+ $ this ->sessionCleaner -> clearFor (( int ) $ customer ->getId ());
1054
1050
$ this ->disableAddressValidation ($ customer );
1055
1051
$ this ->customerRepository ->save ($ customer );
1056
1052
@@ -1619,36 +1615,6 @@ private function getEmailNotification()
1619
1615
}
1620
1616
}
1621
1617
1622
- /**
1623
- * Destroy all active customer sessions by customer id (current session will not be destroyed).
1624
- *
1625
- * Customer sessions which should be deleted are collecting from the "customer_visitor" table considering
1626
- * configured session lifetime.
1627
- *
1628
- * @param string|int $customerId
1629
- * @return void
1630
- */
1631
- private function destroyCustomerSessions ($ customerId )
1632
- {
1633
- $ sessionLifetime = $ this ->scopeConfig ->getValue (
1634
- \Magento \Framework \Session \Config::XML_PATH_COOKIE_LIFETIME ,
1635
- \Magento \Store \Model \ScopeInterface::SCOPE_STORE
1636
- );
1637
- $ dateTime = $ this ->dateTimeFactory ->create ();
1638
- $ activeSessionsTime = $ dateTime ->setTimestamp ($ dateTime ->getTimestamp () - $ sessionLifetime )
1639
- ->format (DateTime::DATETIME_PHP_FORMAT );
1640
- /** @var \Magento\Customer\Model\ResourceModel\Visitor\Collection $visitorCollection */
1641
- $ visitorCollection = $ this ->visitorCollectionFactory ->create ();
1642
- $ visitorCollection ->addFieldToFilter ('customer_id ' , $ customerId );
1643
- $ visitorCollection ->addFieldToFilter ('last_visit_at ' , ['from ' => $ activeSessionsTime ]);
1644
- $ visitorCollection ->addFieldToFilter ('session_id ' , ['neq ' => $ this ->sessionManager ->getSessionId ()]);
1645
- /** @var \Magento\Customer\Model\Visitor $visitor */
1646
- foreach ($ visitorCollection ->getItems () as $ visitor ) {
1647
- $ sessionId = $ visitor ->getSessionId ();
1648
- $ this ->saveHandler ->destroy ($ sessionId );
1649
- }
1650
- }
1651
-
1652
1618
/**
1653
1619
* Set ignore_validation_flag for reset password flow to skip unnecessary address and customer validation
1654
1620
*
0 commit comments