There are many users with random generated password, after transfer from old CMS. While checkout process they see account is existed, try to reset password and after that they see shopping cart is empty. It's embarrasing.
As a workaround, I commented two lines in vendor/magento/module-customer/Model/AccountManagement.php, function resetPassword
$this->sessionManager->destroy();
$this->destroyCustomerSessions($customer->getId());
Did I break anything?
public function resetPassword($email, $resetToken, $newPassword)
{
$customer = $this->customerRepository->get($email);
//Validate Token and new password strength
$this->validateResetPasswordToken($customer->getId(), $resetToken);
$this->checkPasswordStrength($newPassword);
//Update secure data
$customerSecure = $this->customerRegistry->retrieveSecureData($customer->getId());
$customerSecure->setRpToken(null);
$customerSecure->setRpTokenCreatedAt(null);
$customerSecure->setPasswordHash($this->createPasswordHash($newPassword));
//$this->sessionManager->destroy();
//$this->destroyCustomerSessions($customer->getId());
$this->customerRepository->save($customer);
return true;
}
@evgenyvas you only have to comment out $this->sessionManager->destroy();. The destroyCustomerSessions method destroys customer sessions except the active one. But the active one is destroyed in $this->sessionManager->destroy();.
This appears to be introduced in 2.2.3; https://github.com/magento/magento2/blame/a952969a8c08928d356fab8d0fb35f4dbe5fe9ce/app/code/Magento/Customer/Model/AccountManagement.php#L613
This is obviously very annoying for customers.
For now, I just use a composer patch to fix this;
From 1de4b953e0da7ee29d586d770d79d857c3c9ca33 Mon Sep 17 00:00:00 2001
From: peterjaap <[email protected]>
Date: Tue, 22 May 2018 14:33:51 +0200
Subject: [PATCH 1/1] Uncommented destroying of active session after resetting
password
Signed-off-by: peterjaap <[email protected]>
---
Model/AccountManagement.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Model/AccountManagement.php b/Model/AccountManagement.php
index c1231a1..4469e5e 100644
--- a/Model/AccountManagement.php
+++ b/Model/AccountManagement.php
@@ -596,7 +596,7 @@ class AccountManagement implements AccountManagementInterface
$customerSecure->setRpToken(null);
$customerSecure->setRpTokenCreatedAt(null);
$customerSecure->setPasswordHash($this->createPasswordHash($newPassword));
- $this->sessionManager->destroy();
+// $this->sessionManager->destroy();
$this->destroyCustomerSessions($customer->getId());
$this->customerRepository->save($customer);
--
2.17.0
Hi @evgenyvas thank you for your report.
We've acknowledged the issue and added to our backlog.
@engcom-backlog-nazar wasn't this issue fixed by https://github.com/magento/magento2/pull/14973 ? It looks like duplicate of https://github.com/magento/magento2/issues/12362
Hi @ihor-sviziev No, just checked now still exist this issue
@ihor-sviziev This PR can fix this issue-> https://github.com/magento/magento2/pull/17517
Backward patch for 2.2.6;
diff --git a/Model/AccountManagement.php b/Model/AccountManagement.php
index 8f25651..6e40f1a 100644
--- a/Model/AccountManagement.php
+++ b/Model/AccountManagement.php
@@ -670,7 +670,7 @@ class AccountManagement implements AccountManagementInterface
$customerSecure->setRpTokenCreatedAt(null);
$customerSecure->setPasswordHash($this->createPasswordHash($newPassword));
$this->getAuthentication()->unlock($customer->getId());
- $this->sessionManager->destroy();
+// $this->sessionManager->destroy();
$this->destroyCustomerSessions($customer->getId());
$this->customerRepository->save($customer);
--
2.17.1
Backward patch for 2.2.7;
diff --git a/Model/AccountManagement.php b/Model/AccountManagement.php
index 8f25651..404d5e8 100644
--- a/Model/AccountManagement.php
+++ b/Model/AccountManagement.php
@@ -670,7 +670,7 @@ class AccountManagement implements AccountManagementInterface
$customerSecure->setRpTokenCreatedAt(null);
$customerSecure->setPasswordHash($this->createPasswordHash($newPassword));
$this->getAuthentication()->unlock($customer->getId());
- $this->sessionManager->destroy();
+ // $this->sessionManager->destroy(); // uncommented by patch
$this->destroyCustomerSessions($customer->getId());
$this->customerRepository->save($customer);
--
2.17.1
The same error on Magento 2.2.7
This commit: https://github.com/magento/magento2/commit/bc8d3d5d0ead9779cb22d19201cd731719a79b0c does not fix this error
Backward patch for 2.2.8;
diff --git a/Model/AccountManagement.php b/Model/AccountManagement.php
index 6387555..a753a7e 100644
--- a/Model/AccountManagement.php
+++ b/Model/AccountManagement.php
@@ -690,7 +690,7 @@ class AccountManagement implements AccountManagementInterface
$customerSecure->setPasswordHash($this->createPasswordHash($newPassword));
$this->getAuthentication()->unlock($customer->getId());
$this->destroyCustomerSessions($customer->getId());
- $this->sessionManager->destroy();
+ // $this->sessionManager->destroy(); // uncommented by patch
$this->customerRepository->save($customer);
return true;
--
2.17.1
Hello @evgenyvas @peterjaap @hryvinskyi @maximbaibakov @LucasCalazans
Thank you for contribution and collaboration!
The corresponding internal ticket MAGETWO-93628was fixed and closed by Magento team
Delivered to 2.3-develop branch and should be available with 2.3.2 release
Please see details in the next commits:
Internal ticket MAGETWO-93627 currently in the delivery queue and will be merged into 2.2-develop soon.
Should be available with 2.2.9 release
@sdzhepa please establish practice of squashing changes properly, is not so easy to understand what happened there from 5 commits.
Hi @orlangur , we'll reach out our core teams with your suggestion. Thank you for the input.
Most helpful comment
@sdzhepa please establish practice of squashing changes properly, is not so easy to understand what happened there from 5 commits.