注册在洋红色中不起作用


Registration not working in magento

magento 1.9X

我正在使用下面的 ref 来创建 ajax 登录/注册弹出窗口。登录工作正常。但无法注册。


http://fastdivision.com/2012/03/29/diy-magento-create-ajax-login-registration-forms-for-your-magento-theme/它给出了相同的错误弹出窗口"请确保您的密码匹配"。即使我使用现有的电子邮件.同样的弹出错误出现。

配置.xml

<?xml version="1.0"?>
<config>
<modules>
    <FastDivision_QuickLogin>
        <version>1.0.0</version>
    </FastDivision_QuickLogin>
</modules>
<frontend>
    <routers>
        <customer>
            <args>
                <modules>
                    <FastDivision_QuickLogin before="Mage_Customer">FastDivision_QuickLogin_Customer</FastDivision_QuickLogin>
                    <!--<FastDivision_QuickLogin before="Mage_Customer_Account">FastDivision_QuickLogin_Customer</FastDivision_QuickLogin>
                    <FastDivision_QuickLogin before="Mage_Customer_AccountController">FastDivision_QuickLogin_Customer</FastDivision_QuickLogin>-->
                </modules>
            </args>
        </customer>
    </routers>
</frontend>
</config>

帐户控制器.php

<?php
// Require the core controller file that you're planning to override
require_once('Mage/Customer/controllers/AccountController.php');
// The class name follows this format:
// YOURPACKAGE_YOUREXTENSION_COREMODULEFOLDER_CONTROLLERFILENAME
// We extend the original Mage_Customer_AccountController class to inherit unused actions and override specific actions
class FastDivision_QuickLogin_Customer_AccountController extends Mage_Customer_AccountController
{
// Code referenced from AccountController.php
public function loginPostAction()
{
    if(!$this->getRequest()->isXmlHttpRequest()) {
        if ($this->_getSession()->isLoggedIn()) {
            $this->_redirect('*/*/');
            return;
        }
    }
    $session = $this->_getSession();
    if($this->getRequest()->isXmlHttpRequest()) {
        // Report exceptions via JSON
        $ajaxExceptions = array();
    }
    if ($this->getRequest()->isPost()) {
        $login = $this->getRequest()->getPost('login');
        if (!empty($login['username']) && !empty($login['password'])) {
            try {
                $session->login($login['username'], $login['password']);
                if ($session->getCustomer()->getIsJustConfirmed()) {
                    $this->_welcomeCustomer($session->getCustomer(), true);
                }
            } catch (Mage_Core_Exception $e) {
                if($this->getRequest()->isXmlHttpRequest()) {
                    $messages = array_unique(explode("'n", $e->getMessage()));
                    foreach ($messages as $message) {
                        $ajaxExceptions['exceptions'][] = $message;
                    }
                } else {
                    switch ($e->getCode()) {
                        case Mage_Customer_Model_Customer::EXCEPTION_EMAIL_NOT_CONFIRMED:
                            $value = Mage::helper('customer')->getEmailConfirmationUrl($login['username']);
                            $message = Mage::helper('customer')->__('This account is not confirmed. <a href="%s">Click here</a> to resend confirmation email.', $value);
                            break;
                        case Mage_Customer_Model_Customer::EXCEPTION_INVALID_EMAIL_OR_PASSWORD:
                            $message = $e->getMessage();
                            break;
                        default:
                            $message = $e->getMessage();
                    }
                    $session->addError($message);
                }
                $session->setUsername($login['username']);
            } catch (Exception $e) {
                // Mage::logException($e); // PA DSS violation: this exception log can disclose customer password
            }
        } else {
            if($this->getRequest()->isXmlHttpRequest()) {
                $ajaxExceptions['exceptions'][] = 'Login and password are required.';
            } else {
                $session->addError($this->__('Login and password are required.'));
            }
        }
    }
    if($this->getRequest()->isXmlHttpRequest()) {
        // If errors
        if(count($ajaxExceptions)) {
            echo json_encode($ajaxExceptions);
        } else {
            // No Errors
            echo json_encode(array('success' => 'success'));
        }
    } else {
        // Redirect for non-ajax
        $this->_loginPostRedirect();
    }
}
// Create Account
public function createPostAction()
{
    if($this->getRequest()->isXmlHttpRequest()) {
        // Report exceptions via JSON
        $ajaxExceptions = array();
    }
    $session = $this->_getSession();
    if ($session->isLoggedIn()) {
        $this->_redirect('*/*/');
        return;
    }
    $session->setEscapeMessages(true); // prevent XSS injection in user input
    if ($this->getRequest()->isPost()) {
        $errors = array();
        if (!$customer = Mage::registry('current_customer')) {
            $customer = Mage::getModel('customer/customer')->setId(null);
        }
        /* @var $customerForm Mage_Customer_Model_Form */
        $customerForm = Mage::getModel('customer/form');
        $customerForm->setFormCode('customer_account_create')
            ->setEntity($customer);
        $customerData = $customerForm->extractData($this->getRequest());
        if ($this->getRequest()->getParam('is_subscribed', false)) {
            $customer->setIsSubscribed(1);
        }
        /**
         * Initialize customer group id
         */
        $customer->getGroupId();
        if ($this->getRequest()->getPost('create_address')) {
            /* @var $address Mage_Customer_Model_Address */
            $address = Mage::getModel('customer/address');
            /* @var $addressForm Mage_Customer_Model_Form */
            $addressForm = Mage::getModel('customer/form');
            $addressForm->setFormCode('customer_register_address')
                ->setEntity($address);
            $addressData    = $addressForm->extractData($this->getRequest(), 'address', false);
            $addressErrors  = $addressForm->validateData($addressData);
            if ($addressErrors === true) {
                $address->setId(null)
                    ->setIsDefaultBilling($this->getRequest()->getParam('default_billing', false))
                    ->setIsDefaultShipping($this->getRequest()->getParam('default_shipping', false));
                $addressForm->compactData($addressData);
                $customer->addAddress($address);
                $addressErrors = $address->validate();
                if (is_array($addressErrors)) {
                    $errors = array_merge($errors, $addressErrors);
                }
            } else {
                $errors = array_merge($errors, $addressErrors);
            }
        }
        try {
            $customerErrors = $customerForm->validateData($customerData);
            if ($customerErrors !== true) {
                $errors = array_merge($customerErrors, $errors);
            } else {
                $customerForm->compactData($customerData);
                $customer->setPassword($this->getRequest()->getPost('password'));
                $customer->setConfirmation($this->getRequest()->getPost('confirmation'));
                $customerErrors = $customer->validate();
                if (is_array($customerErrors)) {
                    $errors = array_merge($customerErrors, $errors);
                }
            }
            $validationResult = count($errors) == 0;
            if (true === $validationResult) {
                $customer->save();
                Mage::dispatchEvent('customer_register_success',
                    array('account_controller' => $this, 'customer' => $customer)
                );
                if ($customer->isConfirmationRequired()) {
                    $customer->sendNewAccountEmail(
                        'confirmation',
                        $session->getBeforeAuthUrl(),
                        Mage::app()->getStore()->getId()
                    );
                    $session->addSuccess($this->__('Account confirmation is required. Please, check your email for the confirmation link. To resend the confirmation email please <a href="%s">click here</a>.', Mage::helper('customer')->getEmailConfirmationUrl($customer->getEmail())));
                    if($this->getRequest()->isXmlHttpRequest()) {
                        echo json_encode(array('success' => $this->__('Account confirmation is required. Please, check your email for the confirmation link. To resend the confirmation email please <a href="%s">click here</a>.', Mage::helper('customer')->getEmailConfirmationUrl($customer->getEmail()))));
                    } else {
                        $this->_redirectSuccess(Mage::getUrl('*/*/index', array('_secure'=>true)));
                    }
                    return;
                } else {
                    $session->setCustomerAsLoggedIn($customer);
                    $url = $this->_welcomeCustomer($customer);
                    if($this->getRequest()->isXmlHttpRequest()) {
                        echo json_encode(array('success' => 'success'));
                    } else {
                        $this->_redirectSuccess($url);
                    }
                    return;
                }
            } else {
                $session->setCustomerFormData($this->getRequest()->getPost());
                if(!$this->getRequest()->isXmlHttpRequest()) {
                    if (is_array($errors)) {
                        foreach ($errors as $errorMessage) {
                            $session->addError($errorMessage);
                        }
                    } else {
                        $session->addError($this->__('Invalid customer data'));
                    }
                } else {
                    if (is_array($errors)) {
                        foreach ($errors as $errorMessage) {
                            $ajaxExceptions['exceptions'][] = $errorMessage;
                        }
                    } else {
                        $ajaxExceptions['exceptions'][] = 'Invalid customer data';
                    }
                }
            }
        } catch (Mage_Core_Exception $e) {
            $session->setCustomerFormData($this->getRequest()->getPost());
            if ($e->getCode() === Mage_Customer_Model_Customer::EXCEPTION_EMAIL_EXISTS) {
                $url = Mage::getUrl('customer/account/forgotpassword');
                $message = $this->__('There is already an account with this email address. If you are sure that it is your email address, <a href="%s">click here</a> to get your password and access your account.', $url);
                $session->setEscapeMessages(false);
            } else {
                $message = $e->getMessage();
            }
            if(!$this->getRequest()->isXmlHttpRequest()) {
                $session->addError($message);
            } else {
                $messages = array_unique(explode("'n", $e->getMessage()));
                foreach ($messages as $message) {
                    $ajaxExceptions['exceptions'][] = $message;
                }
            }
        } catch (Exception $e) {
            if(!$this->getRequest()->isXmlHttpRequest()) {
                $session->setCustomerFormData($this->getRequest()->getPost())
                ->addException($e, $this->__('Cannot save the customer.'));
            } else {
                $ajaxExceptions['exceptions'][] = 'Cannot save the customer.';
            }
        }
    }
    if($this->getRequest()->isXmlHttpRequest()) {
        echo json_encode($ajaxExceptions);
    } else {
        $this->_redirectError(Mage::getUrl('*/*/create', array('_secure' => true)));
    }
}
}

quick_login.phtml

    <div id="login-modal" class="modal-window">
  <div id="login-modal-content">
    <div id="signup-box">
  <h1>Register</h1>
  <p><a href="#" id="already-registered-link">Already registered? Click here to sign in.</a></p>
  <form action="<?php echo Mage::getBaseUrl() ?>customer/account/createpost/" method="post" id="signup-form" class="site-form" onsubmit="return false">
    <ul class="form-list">
      <li class="fields">
          <div class="field first-field">
              <label for="firstname" class="required"><?php echo $this->__('First Name') ?><em>*</em></label>
              <div class="input-box">
                  <input type="text" name="firstname" id="firstname" class="input-text validate-email required-entry" />
              </div>
          </div>
          <div class="field">
              <label for="last_name" class="required"><?php echo $this->__('Last Name') ?><em>*</em></label>
              <div class="input-box">
                  <input type="text" name="lastname" id="lastname" class="input-text validate-email required-entry" />
              </div>
          </div>
          <div class="field">
              <label for="email_address" class="required"><?php echo $this->__('Email') ?><em>*</em></label>
              <div class="input-box">
                  <input type="text" name="email" id="email_address" class="input-text validate-email required-entry" />
              </div>
          </div>
          <div class="field">
              <label for="password" class="required"><?php echo $this->__('Password') ?><em>*</em></label>
              <div class="input-box">
                  <input type="password" name="password" id="password" title="<?php echo $this->__('Password') ?>" class="input-text required-entry validate-password" />
              </div>
          </div>
          <div class="field">
              <label for="confirmation" class="required"><?php echo $this->__('Confirm Password') ?><em>*</em></label>
              <div class="input-box">
                  <input type="password" name="confirmation" title="<?php echo $this->__('Confirm Password') ?>" id="confirmation" class="input-text required-entry validate-cpassword" />
              </div>
          </div>
      </li>
    </ul>
    <button type="submit" title="Submit" class="action-button"><span>Create Account</span></button>
  </form>
</div>
<div id="login-box">
  <h1>Login</h1>
  <p><?php echo $this->__('If you have an account with us, please log in.') ?></p>
  <p><a href="#" id="need-account-link">Need an account? Click here to register.</a></p>
  <form action="<?php echo Mage::getBaseUrl() ?>customer/account/loginPost/" method="post" id="login-form" class="site-form" onsubmit="return false">
    <ul class="form-list">
         <li class="field">
             <label for="email" class="required"><?php echo $this->__('Email') ?><em>*</em></label>
             <div class="input-box">
                 <input type="text" name="login[username]" value="<?php echo $this->htmlEscape($this->getUsername()) ?>" id="email" class="input-text" title="<?php echo $this->__('Email Address') ?>" />
             </div>
         </li>
         <li class="field">
             <label for="pass" class="required"><?php echo $this->__('Password') ?><em>*</em></label>
             <div class="input-box">
                 <input type="password" name="login[password]" class="input-text" id="pass" title="<?php echo $this->__('Password') ?>" />
             </div>
         </li>
     </ul>
      <button type="submit" class="action-button action-button-no-arrow" title="<?php echo $this->__('Login') ?>" name="send" id="send2"><span><?php echo $this->__('Login') ?></span></button>&nbsp;&nbsp;
      <a href="<?php echo $this->getForgotPasswordUrl() ?>" class="small"><?php echo $this->__('Forgot Your Password?') ?></a>
       </form>
    </div>
  </div>
  <a id="close_x" class="close" href="#"><i class="fa fa-close"></i></a>
  <script type="text/javascript">
  //<![CDATA[
  var dataForm = new VarienForm('login-form', true);
  //]]>
  </script>
</div>

正如我从您收到的错误中看到的那样,该问题是由缺少的"密码确认"表单触发的。

即使您决定隐藏它,也必须使用它才能在控制器中复制密码,直到用户在保存之前进行验证。

在创建后操作方法的出口处检查数据:

var_dump($this->getRequest()->getPost());

或通过调试(如果您正在使用它)。

该数组应具有以下视图:https://gyazo.com/52d5c7fe80316b9f8f3773fcfa1f6462

这是必需参数(填写的参数)的最小值。

如果数组不包含带有确认键的元素以及与密码对应的含义,则它将被忽略并跳过模板 (.phtml) 中的某个位置。

如果它仍然存在,您应该检查 createPostAction 中的整组已实现操作,并在调用 Mage_Customer_Model_Customer::validate() 之前找到删除它的位置(这是生成错误的位置)。

如果在不使用 AJAX 并使用"提交"选项的情况下发送表单,则应删除此表单属性

 onsubmit="return false;"

Magento 1.9中,每当客户在店面结账或注册时,即使您的密码和确认密码字段相同,也会弹出"请确保您的密码匹配"。在Magento版本1.9中,验证确认类"Mage_Customer_Model_Customer"方法中的密码值 validate() 进行了一些更改。

以前:

 $confirmation = $this->getConfirmation();

后:

$confirmation = $this->getPasswordConfirmation();

因此,如果您在结帐和注册时遇到相同的问题,请将行更改为

$confirmation = $this->getConfirmation();