After updating to Magento 2.4.4, clicking the "Set new password" link in the "Forgot password mail" send by the system the link always shows as expired?!
Setting of "Recovery Link Expiration Period (hours) = 2 hours"
Seems like a bug to me. Does anyone see what is wrong in native Magento CreatePassword.php for example? Replacing "token" with "amp;token" does not help (as suggested by some for earlier versions)
CreatePassword.php in vendor/magento/module-customer/Controller/Account is as follows in Magento 2.4.4:
public function __construct(
Context $context,
Session $customerSession,
PageFactory $resultPageFactory,
AccountManagementInterface $accountManagement,
ConfirmCustomerByToken $confirmByToken = null,
GetCustomerByToken $getByToken = null,
CustomerRepositoryInterface $customerRepository = null
) {
$this->session = $customerSession;
$this->resultPageFactory = $resultPageFactory;
$this->accountManagement = $accountManagement;
$this->confirmByToken = $confirmByToken
?? ObjectManager::getInstance()->get(ConfirmCustomerByToken::class);
$this->getByToken = $getByToken
?? ObjectManager::getInstance()->get(GetCustomerByToken::class);
$this->customerRepository = $customerRepository
?? ObjectManager::getInstance()->get(CustomerRepositoryInterface::class);
parent::__construct($context);
}
/**
* Resetting password handler
*
* @return Redirect|Page
*/
public function execute()
{
$resetPasswordToken = (string)$this->getRequest()->getParam('token');
$customerId = (int)$this->getRequest()->getParam('id');
$isDirectLink = $resetPasswordToken != '';
if (!$isDirectLink) {
$resetPasswordToken = (string)$this->session->getRpToken();
$customerId = (int)$this->session->getRpCustomerId();
}
try {
$this->accountManagement->validateResetPasswordLinkToken($customerId, $resetPasswordToken);
$this->confirmByToken->resetCustomerConfirmation($customerId);
// Extend token validity to avoid expiration while this form is
// being completed by the user.
$customer = $this->customerRepository->getById($customerId);
$this->accountManagement->changeResetPasswordLinkToken($customer, $resetPasswordToken);
if ($isDirectLink) {
$this->session->setRpToken($resetPasswordToken);
$this->session->setRpCustomerId($customerId);
$resultRedirect = $this->resultRedirectFactory->create();
$resultRedirect->setPath('*/*/createpassword');
return $resultRedirect;
} else {
/** @var Page $resultPage */
$resultPage = $this->resultPageFactory->create();
$resultPage->getLayout()
->getBlock('resetPassword')
->setResetPasswordLinkToken($resetPasswordToken)
->setRpCustomerId($customerId);
return $resultPage;
}
} catch (\Exception $exception) {
$this->messageManager->addErrorMessage(__('Your password reset link has expired.'));
/** @var Redirect $resultRedirect */
$resultRedirect = $this->resultRedirectFactory->create();
$resultRedirect->setPath('*/*/forgotpassword');
return $resultRedirect;
}
}