magento登陆

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();

    }

    }

时间: 2024-08-27 10:30:02

magento登陆的相关文章

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

安装过magento的几个版本,安装好后在登陆后台的时候都遇到了点问题,用户名和密码都输入正确,就是登陆不了后台,经过研究发现,登陆不了后台的主要是因为magento自身缓存设置的问题,最模板解决方法如下: magento登陆不了后台可以尝试以下几种方法解决: 方法一,用FF登陆后台,在 System—Configuration-Web-Session Cookie management….timeout 改为:86400 如果方法一不行,就用方法二 方法二:仍不能登陆请打开文件 app/cod

magento启用SSL改http成https

Magento是电子商务网站,对于网站的用户信息安全来说,让Magento使用SSL连接是一个很好的解决方案.如果在页面的边栏或者底部放上些表明本站使用安全连接的图片,显得更专业,让客户有安全感,对于magento网站也是一个很好的宣传. Magento SSL是在需要输入账户密码或者涉及个人隐私的页面才会是https://www…..的安全访问网址,有登录页,结账页,用户面板页面.其余不涉及用户账户信息的magento页面是http://www…..普通连接来访问的,比如首页,产品列表页,产品

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 useful UX feature. In this tutorial, I will explain how to create such a dropdown in a few minutes! 并不是每一个站都用下拉登陆菜单,但对某些时候确实非常实用.这次我们就来体验一下如何给Magento

magento后台不能登陆

本人magento 1.7.2 在修改后台登陆链接可以登陆 而后用mysql update在admin_user 修改登陆密码后不能登陆 尝试用删除var/session 修改app/..../Varien.php cookie字段还是无法解决 最好我尝试用后台点击  忘记密码  然后去修改密码  居然成功登陆了

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

Inchoo提供magento和facebook连接的扩展,可以到http://inchoo.net/ecommerce/magento/facebook-connect-magento-extension/上去下载,安装完后记得清空缓存并运行magento. 摘自 http://blog.csdn.net/ddjohn/article/details/6605290

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

1. magento在索引的时候用shell,有时候会报错: General error: 1205 Lock wait timeout exceeded 这个时候,是因为行锁的原因,在表中您直接用sql执行更新,会报这个错,也就是说这个错是mysql报的. 需要吧表index_process解锁 如果您想快速的解决,那么,把表导入,修改,删除数据库中index_process表,重新导入,OK,行锁会消失. 网上也有把index的mode改为手动,索引完改回来,好像还是有问题,报这个错就是my

magento后台登陆404的解决方案

(1)执行如下sql SET SQL_SAFE_UPDATES=0; SET FOREIGN_KEY_CHECKS=0; UPDATE `core_store` SET store_id = 0 WHERE code='admin'; UPDATE `core_store_group` SET group_id = 0 WHERE name='Default'; UPDATE `core_website` SET website_id = 0 WHERE code='admin'; UPDATE

php实现微信扫码自动登陆与注册功能

本文实例讲述了php实现微信扫码自动登陆与注册功能.分享给大家供大家参考,具体如下: 微信开发已经是现在程序员必须要掌握的一项基本的技术了,其实做过微信开发的都知道微信接口非常的强大做起来也非常的简单,这里我们一起来看一个微信自动登陆注册的例子. php 微信扫码 pc端自动登陆注册 用的接口scope 是snsapi_userinfo,微信登陆一个是网页授权登陆,另一个是微信联合登陆 网页授权登陆:http://mp.weixin.qq.com/wiki/17/c0f37d5704f0b647

magento常用插件

magento插件插件集锦: 1. 删除订单:BoutikCircus_DeleteOrders URL:http://www.magentocommerce.com/e ... 4562/em_deleteorder 另一个同类插件: URL:http://www.magentocommerce.com/m ... yomind_orderseraser 2. 后台管理产品显示图片:TBT_Enhancedgrid URL:http://www.magentocommerce.com/m ..