magento判断用户登录

Magento 登陆之后返回登录之前的页面

magento 在登陆后一般会自动跳转到 My Account 页面

但是经常会有需求 就是登陆自动跳转到 之前的页面里面

工具/原料

  • php+mysql+apache

方法/步骤

  1.  

    只要加代码

    Mage::getSingleton('customer/session')->setBeforeAuthUrl(Mage::getUrl('*/*/*', array('_secure'=>true)));或

    Mage::getSingleton('customer/session')->setBeforeAuthUrl(Mage::helper("core/url")->getCurrentUrl());

    在之前的页面 就可以实现这个功能

  2.  

    <!-- <?php //判断用户是否是登录用户,如果不是登录用户就跳转到登录页面,登录成就进入网站的页面?>-->

    <?php

    Mage::getSingleton('customer/session')->setBeforeAuthUrl($this->getRequest()->getRequestUri());  //save requested URL for later redirection

    if(!Mage::getSingleton('customer/session')->isLoggedIn()) {  // if not logged in

    header("Status: 301");

    //  header('Location: '.Mage::helper('core/url')->getHomeUrl(customer/account/login)) ;  // send to the login page

    header('Location:'.Mage::getBaseUrl('web').'index.php/customer/account/login/'           ) ;

    exit;

    }

    ?>

    magento在购物车中判断用户登录,如果没有登录就跳转到登录页面,红色字体代表新增代码

    首先进入app/code/local/idev/onestepchekcout/controllers/indexcontroller.php文件

    加上一个

    if(Mage::getSingleton( 'customer/session' )->isLoggedIn())

    {判断和

    else

    {       $redirect=Mage::getBaseUrl().'customer/account/create/';

    Mage::app()->getFrontController()->getResponse()->setRedirect($redirect)->sendResponse();//这个是需要跳转到的登录页面或者是注册页面

    }

    即可

    放的位置代码如下:

    public function indexAction() {

    if(Mage::getSingleton( 'customer/session' )->isLoggedIn())

    {

    $quote = $this->getOnepage()->getQuote();

    if (!$quote->hasItems() || $quote->getHasError()) {

    $this->_redirect('checkout/cart');

    return;

    }

    if (!$quote->validateMinimumAmount()) {

    $error = Mage::getStoreConfig('sales/minimum_order/error_message');

    Mage::getSingleton('checkout/session')->addError($error);

    $this->_redirect('checkout/cart');

    return;

    }

    $this->loadLayout();

    if(Mage::helper('onestepcheckout')->isEnterprise() && Mage::helper('customer')->isLoggedIn()){

    $customerBalanceBlock = $this->getLayout()->createBlock('enterprise_customerbalance/checkout_onepage_payment_additional', 'customerbalance', array('template'=>'onestepcheckout/customerbalance/payment/additional.phtml'));

    $customerBalanceBlockScripts = $this->getLayout()->createBlock('enterprise_customerbalance/checkout_onepage_payment_additional', 'customerbalance_scripts', array('template'=>'onestepcheckout/customerbalance/payment/scripts.phtml'));

    $rewardPointsBlock = $this->getLayout()->createBlock('enterprise_reward/checkout_payment_additional', 'reward.points', array('template'=>'onestepcheckout/reward/payment/additional.phtml', 'before' => '-'));

    $rewardPointsBlockScripts = $this->getLayout()->createBlock('enterprise_reward/checkout_payment_additional', 'reward.scripts', array('template'=>'onestepcheckout/reward/payment/scripts.phtml', 'after' => '-'));

    $this->getLayout()->getBlock('choose-payment-method')

    ->append($customerBalanceBlock)

    ->append($customerBalanceBlockScripts)

    ->append($rewardPointsBlock)

    ->append($rewardPointsBlockScripts)

    ;

    }

    $this->renderLayout();

    }

    else

    {       $redirect=Mage::getBaseUrl().'customer/account/create/';

    Mage::app()->getFrontController()->getResponse()->setRedirect($redirect)->sendResponse();

    }

    }

  3.  

    判断用户是否从结算页面当中进入的,如果是从结算页面当中进入登录的或者是注册的那么需要进入下一步操作

    首先在form表单中加个<input name="xxx" value="xxxx" type="hidden"/>代码如下:

    <form id="login-form" action="http://www.wellsupplier.com/index.php/customer/account/loginPost/" method="post">

    <input type="hidden" value="check-out" name="cart-name"/>

    或者跳转到进入登录注册页面前一页

    <?php echo $currlink=substr($_SERVER['HTTP_REFERER'],27); ?>

    <input type="hidden" value="<?php echo $currlink;?>" name="cart-name"/>

    然后去loginPostAction方法中进行判断,代码路径D:\Program Files\wamp\www\focalpriced\app\code\core\Mage\Customer\controllers\accountcontrollers.php文件

    然后找到public function loginPostAction()方法 ;

    public function loginPostAction()

    {

    $chac=$this->getRequest()->getParam("cart-name");  //获取表单的传过来的值

    if ($this->_getSession()->isLoggedIn()) {

    $this->_redirect('*/*/');

    return;

    }

    $session = $this->_getSession();

    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) {

    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 {

    $session->addError($this->__('Login and password are required.'));

    }

    }

    if(isset($chac)){      //判断表单的值进行跳转

    $redirect=Mage::getBaseUrl().$chac;

    Mage::app()->getFrontController()->getResponse()->setRedirect($redirect)->sendResponse();

    } else  {

    $this->_loginPostRedirect();

    }

    }

magento登陆的更多相关文章

  1. 解决magento后台无法登陆/登陆没有反应的方法

    安装过magento的几个版本,安装好后在登陆后台的时候都遇到了点问题,用户名和密码都输入正确,就是登陆不了后台,经过研究发现,登陆不了后台的主要是因为magento自身缓存设置的问题,最模板解决方法 ...

  2. magento

     打开 magento/app/code/core/Mage/Core/Model/Session/Abstract/varien.php//if (isset($cookieParams['doma ...

  3. magento启用SSL改http成https

    Magento是电子商务网站,对于网站的用户信息安全来说,让Magento使用SSL连接是一个很好的解决方案.如果在页面的边栏或者底部放上些表明本站使用安全连接的图片,显得更专业,让客户有安全感,对于 ...

  4. Magento获取当前页面URL地址

    Magento获取当前页面URL地址 http://www.sunhaibing.com/?p=1260 在Magento中,可以通过core/url助手类中的getCurrentUrl()方法获取当 ...

  5. Magento添加一个下拉登陆菜单Create Magento Dropdown Login in a few minutes

    Dropdown login forms are not a feature many online stores use, but in some cases they could be quite ...

  6. 用facebook账号登陆到你的Magento网店

    Inchoo提供magento和facebook连接的扩展,可以到http://inchoo.net/ecommerce/magento/facebook-connect-magento-extens ...

  7. magento后台登陆被锁定 索引报错的解决:General error: 1205 Lock wait timeout

    1. magento在索引的时候用shell,有时候会报错: General error: 1205 Lock wait timeout exceeded 这个时候,是因为行锁的原因,在表中您直接用s ...

  8. Magento在IE下登陆不了后台,在Firefox下正常

    目前的解决办法如下: 方法一,用FF登陆后台,在 System—Configuration-Web-Session Cookie management....timeout 改为:86400 方法二: ...

  9. magento后台无法登陆的问题

    解决方法: 打开 magento/app/code/core/Mage/Core/Model/Session/Abstract/varien.php 将// set session cookie pa ...

随机推荐

  1. SQLSERVER 免费对比数据库结构和数据的工具支持:SQL Server 2012, SQL Server 2008 and SQL Server 2005

    New xSQL Schema Compare - version 5 Compare the schemas of two SQL Server databases, review differen ...

  2. MySQL数据复制到其他主机时报错

    问题1: MySQL server has gone away With statement 原因:SQl insert 插入的语句天长导致 问题2:mysql a bulk size specifi ...

  3. maven多module项目中千万不要引入其它模块的单元測试代码

    本文出处:http://blog.csdn.net/chaijunkun/article/details/35796335,转载请注明. 因为本人不定期会整理相关博文,会对对应内容作出完好. 因此强烈 ...

  4. Javascript 面向对象实践

    踩到了坑,才能学到东西. 记录我在慢慢的转向模块化遇到的问题以及解决的思路. 1.采用立即执行函数,闭包的方式创建模块 html: <!DOCTYPE html> <html lan ...

  5. 使用CocoaPods来做iOS程序的包依赖管理

    前言 每种语言发展到一个阶段,就会出现相应的依赖管理工具, 或者是中央代码仓库.比如 Java: maven,Ivy Ruby: gems Python: pip, easy_install Node ...

  6. JavaScript Array 对象常用方法

    <script type="text/javascript"> //shift:删除原数组的第一项,返回删除元素的值:如果数组为空则返回undefined var ar ...

  7. JAVA eclipse 安装lombok

    1.下载lombok http://projectlombok.org/download.html 2.点击安装: 如果eclipse没有安装到默认目录,那么需要点击Specify选择eclipse的 ...

  8. 2016 博客导读总结 &amp; 个人感悟

    此文着笔之时.2017已经在眼前了.预计等我写完,2017已经到了. 二次编辑于2017年1月1日早11点. 关于2016的感悟.十二月初就想写,当时认为是有点太早了,只是却思绪如泉涌. 且那时候才刚 ...

  9. GoldenGate安装与卸载

    软件下载 http://www.oracle.com/technetwork/middleware/goldengate/downloads/index.html 安装 卸载(Using Oracle ...

  10. 索引范围扫描(INDEX RANGE SCAN)

    索引范围扫描(INDEX RANGE SCAN)适用于所有类型的B树索引,当扫描的对象是唯一性索引时,此时目标SQL的where条件一定是范围查询(谓词条件为 BETWEEN.<.>等): ...