Jhanvee S
Jhanvee S

Reputation: 9

How to send password reset link in auto generated email template in magento

As shown in the screenshot, in the customer information when the password is set from admin and then changes are saved, an email is send to the customer. By default, the new password and account link is send in the email.

What I want to ask is that, is it possible to send the link of password reset also in this email?

I think the template used is:

app/locale/en_US/template/email/password_new.html

I tried to add following:

{{store url="customer/account/resetpassword/" _query_id=$customer.id _query_token=$customer.rp_token}}

But I am getting error on frontend as:

Your password reset link has expired.

Upvotes: 0

Views: 2806

Answers (2)

David Hayes
David Hayes

Reputation: 196

So looks like the reset token is not generate for that email generated from the administrator.

I was able to fix this in 1.9.1.0 by creating a controller override for the app/code/core/Adminhtml/controllers/CustomerController.php files (per these instructions http://inchoo.net/magento/overriding-magento-blocks-models-helpers-and-controllers/ -- Adminhtml controller override section).

Copy the saveAction method to the override.

Inside the saveAction method, look for this block of code around line 351 (original file).

if (!empty($data['account']['new_password'])) {
    $newPassword = $data['account']['new_password'];
    if ($newPassword == 'auto') {
        $newPassword = $customer->generatePassword();
    }
    $customer->changePassword($newPassword);
    $customer->sendPasswordReminderEmail();
}

Change this block to

if (!empty($data['account']['new_password'])) {
    $newPassword = $data['account']['new_password'];
    if ($newPassword == 'auto') {
        // no token generated
        //~ $newPassword = $customer->generatePassword();
        $newResetPasswordLinkToken = Mage::helper('admin')->generateResetPasswordLinkToken();
        $customer->changeResetPasswordLinkToken($newResetPasswordLinkToken);
    }
    $customer->changePassword($newPassword);
    $customer->sendPasswordReminderEmail();
}

To have the token generated and added to the password reset email from the admin.

Upvotes: 0

rajatsaurastri
rajatsaurastri

Reputation: 653

Yes you can -- You can generate new reset password token & set it to customerObject - Try something like

/** @var $customer Mage_Customer_Model_Customer */
$customer = Mage::getModel('customer/customer')
    ->setWebsiteId(Mage::app()->getStore()->getWebsiteId())
    ->loadByEmail("[email protected]"); //change the email
if ($customer->getId()) {
    try {
        $newResetPasswordLinkToken =  Mage::helper('customer')->generateResetPasswordLinkToken();
        $customer->changeResetPasswordLinkToken($newResetPasswordLinkToken);
        $customer->sendPasswordResetConfirmationEmail();
    } catch (Exception $exception) {
        Mage::log($exception);
    }
}

Upvotes: 1

Related Questions