0

I am trying to reset my password as a customer. After going to the link received from email when i try to reset my password i am getting this error. See https://prnt.sc/p7ksmr.

Can any one help me in this.

namespace Smartwave\Porto\Model;


class AccountManagement extends \Magento\Customer\Model\AccountManagement
{

private function matchCustomerByRpToken(string $rpToken):CustomerInterface
{
    $this->searchCriteriaBuilder->addFilter(
        'rp_token',
        $rpToken
    );
    $this->searchCriteriaBuilder->setPageSize(1);
    $found = $this->customerRepository->getList(
        $this->searchCriteriaBuilder->create()
    );
    if ($found->getTotalCount() > 1) {
        //Failed to generated unique RP token
        throw new ExpiredException(
            new Phrase('Reset password token expired.')
        );
    }
    if ($found->getTotalCount() === 0) {
        //Customer with such token not found.
        throw NoSuchEntityException::singleField(
            'rp_token',
            $rpToken
        );
    }
    //Unique customer found.
    return $found->getItems()[0];
}

public function resetPassword($email, $resetToken, $newPassword)
{
    if (!$email) {
        $customer = $this->matchCustomerByRpToken($resetToken);
        $email = $customer->getEmail();
    } else {
        $customer = $this->customerRepository->get($email);
    }
    //Validate Token and new password strength
    $this->validateResetPasswordToken($customer->getId(), $resetToken);
    $this->credentialsValidator->checkPasswordDifferentFromEmail(
        $email,
        $newPassword
    );
    $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); */
$this->destroyCustomerSessions($customer->getId());
$this->sessionManager->destroy();
$this->customerRepository->save($customer);

    return true;
}

}

4
  • Your Magento version please?
    – Sumit
    Sep 18 '19 at 5:59
  • @Sumit My magento version is 2.3
    – Nafsss
    Sep 18 '19 at 6:03
  • Any error log you've in the logs file regarding the issue?
    – Sumit
    Sep 18 '19 at 6:30
  • @Sumit. I tried the solution given by Rk Rathod. It worked when i changed directly my core file. But after overriding the model, its not working
    – Nafsss
    Sep 18 '19 at 8:37
1

You need to override the /vendor/magento/module-customer/Model/AccountManagement.php in your theme.

etc/di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="Magento\Customer\Model\AccountManagement"
                type="Vendor\Module\Model\Rewrite\AccountManagement" />
</config>

We need to copy the full AccountManagement.php file as it contains private functions and variables and do the required changes in resetPassword().

Create AccountManagement.php file under Vendor\Module\Model\Rewrite with your code.

Hope it helps!!!

7
  • Getting this error prnt.sc/p7nmh8 when i run setup de:compile command
    – Nafsss
    Sep 18 '19 at 9:21
  • Permission issue, please remove the generated folder content and give permission 777 to the generated folder.
    – Sumit
    Sep 18 '19 at 9:22
  • Removed generated folder and given 777 prmission....still same issue
    – Nafsss
    Sep 18 '19 at 9:26
  • Plz help what to do?
    – Nafsss
    Sep 18 '19 at 9:34
  • Please wait, I'm looking into it on my installation.
    – Sumit
    Sep 18 '19 at 9:35
0

Refernce Link

This is an issue in Magento 2.2.6 (check here)

This patch fixes it.

In app/code/Magento/Customer/Model/AccountManagement.php, in function resetPassword:

BEFORE

    $this->sessionManager->destroy();
    $this->destroyCustomerSessions($customer->getId());
    $this->customerRepository->save($customer);

AFTER

    $this->destroyCustomerSessions($customer->getId());
    $this->sessionManager->destroy();
    $this->customerRepository->save($customer);

sudo rm -rf pub/static/frontend/ pub/static/adminhtml/ pub/static/_requirejs pub/static/deployed_version.txt var/cache var/page_cache var/generation var/view_preprocessed var/session generated/code

sudo php bin/magento setup:upgrade

sudo php bin/magento setup:static-content:deploy -f

sudo php bin/magento cache:flush

And Also Give Permission

16
  • This worked from when i changed from core. After overriding the file its not working
    – Nafsss
    Sep 18 '19 at 7:18
  • please attach code of overriding file
    – Rk Rathod
    Sep 18 '19 at 7:19
  • I Updated my ans
    – Nafsss
    Sep 18 '19 at 7:25
  • define in di.xml ??
    – Rk Rathod
    Sep 18 '19 at 7:26
  • YEs......... <preference for="Magento\Customer\Model\AccountManagement" type="Smartwave\Porto\Model\AccountManagement" />
    – Nafsss
    Sep 18 '19 at 7:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.