当需要性别和/或出生日期时,Magento密码重置错误

时间:2014-02-19 11:49:34

标签: php magento zend-framework passwords reset

我正在运行1.7.0.2 Magento网站。对于本网站,我最近为用户激活了所需的“性别”和“出生日期”选项。这意味着一些现有用户还没有填写他们的性别和出生日期。问题是,如果这些用户中的任何一个忘记​​了密码并尝试重置密码,则会出现以下错误:

The Date of Birth is required.
Gender is required.
Your password reset link has expired.

尝试输入首选新密码并提交此条目后,会发生此错误。

当不需要“性别”和“出生日期”时,密码重置正常。

我在这个主题上只找到了one post,但还没有答案。

1 个答案:

答案 0 :(得分:0)

你需要覆盖 Mage_Customer_AccountController控制器resetPasswordPostAction()操作

覆盖你的函数后

看起来像这样

public function resetPasswordPostAction()
    {
        $resetPasswordLinkToken = (string) $this->getRequest()->getQuery('token');
        $customerId = (int) $this->getRequest()->getQuery('id');
        $password = (string) $this->getRequest()->getPost('password');
        $passwordConfirmation = (string) $this->getRequest()->getPost('confirmation');

        try {
            $this->_validateResetPasswordLinkToken($customerId, $resetPasswordLinkToken);
        } catch (Exception $exception) {
            $this->_getSession()->addError(Mage::helper('customer')->__('Your password reset link has expired.'));
            $this->_redirect('*/*/');
            return;
        }

        $errorMessages = array();
        if (iconv_strlen($password) <= 0) {
            array_push($errorMessages, Mage::helper('customer')->__('New password field cannot be empty.'));
        }
        /** @var $customer Mage_Customer_Model_Customer */
        $customer = Mage::getModel('customer/customer')->load($customerId);

        $customer->setPassword($password);
        $customer->setConfirmation($passwordConfirmation);
        $validationErrorMessages = $customer->validate();
        if (is_array($validationErrorMessages)) {
            //$errorMessages = array_merge($errorMessages, $validationErrorMessages);
        }

        if (!empty($errorMessages)) {
            $this->_getSession()->setCustomerFormData($this->getRequest()->getPost());
            foreach ($errorMessages as $errorMessage) {
                $this->_getSession()->addError($errorMessage);
            }
            $this->_redirect('*/*/resetpassword', array(
                'id' => $customerId,
                'token' => $resetPasswordLinkToken
            ));
            return;
        }

        try {
            // Empty current reset password token i.e. invalidate it
            $customer->setRpToken(null);
            $customer->setRpTokenCreatedAt(null);
            $customer->setConfirmation(null);
            $customer->save();
            $this->_getSession()->addSuccess(Mage::helper('customer')->__('Your password has been updated.'));
            $this->_redirect('*/*/login');
        } catch (Exception $exception) {
            $this->_getSession()->addException($exception, $this->__('Cannot save a new password.'));
            $this->_redirect('*/*/resetpassword', array(
                'id' => $customerId,
                'token' => $resetPasswordLinkToken
            ));
            return;
        }
    }

我上面的功能我已经评论了第646行

$errorMessages = array_merge($errorMessages, $validationErrorMessages);