1

我是magento的新手,我必须做自定义登录页面表单,登录后重定向到帐户信息,我该怎么做?需要magento有经验的人的帮助,

4

1 回答 1

2

在这里我给你骨架代码做登录请检查你的实际代码和文件

登录控制器动作就像

 public function loginAction()
    {
        $session = Mage::getSingleton('customer/session');
        if ($session->isLoggedIn()) {
        // is already login redirect to account page
            return;
        }

        $result = array('success' => false);

        if ($this->getRequest()->isPost())
        {
            $login_data = $this->getRequest()->getPost('login');
            if (empty($login_data['username']) || empty($login_data['password'])) {
                $result['error'] = Mage::helper('onepagecheckout')->__('Login and password are required.');
            }
            else
            {
                try
                {
                    $session->login($login_data['username'], $login_data['password']);
                    $result['success'] = true;
                    $result['redirect'] = Mage::getUrl('*/*/index');
                }
                catch (Mage_Core_Exception $e)
                {
                    switch ($e->getCode()) {
                        case Mage_Customer_Model_Customer::EXCEPTION_EMAIL_NOT_CONFIRMED:
                            $message = Mage::helper('onepagecheckout')->__('Email is not confirmed. <a href="%s">Resend confirmation email.</a>', Mage::helper('customer')->getEmailConfirmationUrl($login_data['username']));
                            break;
                        default:
                            $message = $e->getMessage();
                    }
                    $result['error'] = $message;
                    $session->setUsername($login_data['username']);
                }
            }
        }

        $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
    }

你的表格就像

<?php
$login_url  = $this->getUrl('*/*/login', array('_secure'=>(!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS']==='on')));
$http_mode  = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS']==='on');
if($http_mode)
    $login_url  = str_replace('http:', 'https:', $login_url);  
?>
    <form method="post" id="login-form" action="<?php echo $login_url ?>">
<div class='full'>
                <label>
                    <?php echo $this->__('Email Address') ?>
                </label>
                <sup>*</sup>
                <div class="data_area">
                    <input type="text" name="login[username]" value="<?php echo $this->htmlEscape($this->getUsername()) ?>" id="email" class="input-text required-entry validate-email" title="<?php echo $this->__('Email Address') ?>" />
                </div>
            </div>
<div class='full'>
                <label>
                    <?php echo $this->__('Password') ?>
                </label>
                <sup>*</sup>
                <div class="input-box">
                    <input type="password" name="login[password]" class="input-text required-entry validate-password" id="pass" title="<?php echo $this->__('Password') ?>" />
                </div>
            </div>

<button type="submit" class="button" title="<?php echo $this->__('Login') ?>" name="send" id="send2"><span><span><?php echo $this->__('Login') ?></span></span></button>

 <script type="text/javascript">
    //<![CDATA[
        var loginForm = new VarienForm('login-form', true);
    //]]>
    </script>

上面的示例适用于 ajax,您可以将其转换为示例重定向到控制器中的 myaccount 页面。

于 2013-08-16T10:23:08.807 回答