0

I am trying to reset my password using below code,

$emailid  = $this->post('email_id');
    $customer = Mage::getModel('customer/customer')
            ->setWebsiteId(Mage::app()->getStore()->getWebsiteId())
            ->loadByEmail($emailid);
    if ($customer->getId()) {
        try {
            $newResetPasswordLinkToken =  Mage::helper('customer')->generateResetPasswordLinkToken();
            $customer->changeResetPasswordLinkToken($newResetPasswordLinkToken);
            $customer->sendPasswordResetConfirmationEmail();
            $this->response([
                'status' => true,
                'message' => 'Email sent successfully'
                ], REST_Controller::HTTP_OK); // NOT_FOUND (404) being the HTTP response code
        }catch (Exception $exception) {
            $this->response([
                'status' => false,
                'message' => 'Email ID is not registered with us.'
                ], REST_Controller::HTTP_NOT_FOUND); // NOT_FOUND (404) being the HTTP response code
        }
    }

Above code it's working perfectly, I am getting mail also, But when I click reset password button in the mail, Its showing link expired.

I have noticed the password reset link, they have used two parameters (id, token). In the programmatically generated email, the link has only token, id parameter is missing. I don't know why id not coming.

Can any one help help me to fix this issue. Thanks.

1 Answer 1

0
$emailid = $_POST['email'];
$customer = Mage::getModel('customer/customer')->setWebsiteId(Mage::app()->getStore()->getWebsiteId())->loadByEmail($emailid);
if ($customer->getId()) {
try {
$customerId = $customer->getId();
$newResetPasswordLinkToken =  Mage::helper('customer')->generateResetPasswordLinkToken();
$newResetPasswordLinkCustomerId = Mage::helper('customer')
                    ->generateResetPasswordLinkCustomerId($customerId);
$customer->changeResetPasswordLinkCustomerId($newResetPasswordLinkCustomerId);
$customer->changeResetPasswordLinkToken($newResetPasswordLinkToken);
$customer->sendPasswordResetConfirmationEmail();
}
catch (Exception $exception) {
Mage::log($exception);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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