As a workaround for this, we are rewriting Magento\Customer\Model\AccountManagement resetPassword()
, setting customer as logged in at the end of that function, this way the flow doesn't reach the point where redirect bug occurs
class AccountManagement extends \Magento\Customer\Model\AccountManagement
{
/** Need to copy here, cause of private scope */
private function validateResetPasswordToken($customerId, $resetPasswordLinkToken)
{
$customerRegistry = ObjectManager::getInstance()->get(\Magento\Customer\Model\CustomerRegistry::class);
if (empty($customerId) || $customerId < 0) {
throw new InputException(
__(
'Invalid value of "%value" provided for the %fieldName field.',
['value' => $customerId, 'fieldName' => 'customerId']
)
);
}
if (!is_string($resetPasswordLinkToken) || empty($resetPasswordLinkToken)) {
$params = ['fieldName' => 'resetPasswordLinkToken'];
throw new InputException(__('%fieldName is a required field.', $params));
}
$customerSecureData = $customerRegistry->retrieveSecureData($customerId);
$rpToken = $customerSecureData->getRpToken();
$rpTokenCreatedAt = $customerSecureData->getRpTokenCreatedAt();
if (!Security::compareStrings($rpToken, $resetPasswordLinkToken)) {
throw new InputMismatchException(__('Reset password token mismatch.'));
} elseif ($this->isResetPasswordLinkTokenExpired($rpToken, $rpTokenCreatedAt)) {
throw new ExpiredException(__('Reset password token expired.'));
}
return true;
}
/**
* Using ObjectManager here to simplify the rewrite,
* so we dont't need to define constructor class
*/
public function resetPassword($email, $resetToken, $newPassword)
{
$customerRepository = ObjectManager::getInstance()->get(\Magento\Customer\Api\CustomerRepositoryInterface::class);
$customerRegistry = ObjectManager::getInstance()->get(\Magento\Customer\Model\CustomerRegistry::class);
$customerSession = ObjectManager::getInstance()->get(\Magento\Customer\Model\Session::class);
$customer = $customerRepository->get($email);
//Validate Token and new password strength
$this->validateResetPasswordToken($customer->getId(), $resetToken);
$this->checkPasswordStrength($newPassword);
//Update secure data
$customerSecure = $customerRegistry->retrieveSecureData($customer->getId());
$customerSecure->setRpToken(null);
$customerSecure->setRpTokenCreatedAt(null);
$customerSecure->setPasswordHash($this->createPasswordHash($newPassword));
//$this->sessionManager->destroy();
//$this->destroyCustomerSessions($customer->getId());
$customerRepository->save($customer);
// login customer
$customerSession->setCustomerDataAsLoggedIn($customer);
$customerSession->regenerateId();
return true;
}
}