magento登陆
magento判断用户登录
Magento 登陆之后返回登录之前的页面
magento 在登陆后一般会自动跳转到 My Account 页面
但是经常会有需求 就是登陆自动跳转到 之前的页面里面
工具/原料
- php+mysql+apache
方法/步骤
只要加代码
Mage::getSingleton('customer/session')->setBeforeAuthUrl(Mage::getUrl('*/*/*', array('_secure'=>true)));或
Mage::getSingleton('customer/session')->setBeforeAuthUrl(Mage::helper("core/url")->getCurrentUrl());
在之前的页面 就可以实现这个功能
<!-- <?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();
}
}
判断用户是否从结算页面当中进入的,如果是从结算页面当中进入登录的或者是注册的那么需要进入下一步操作
首先在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登陆的更多相关文章
- 解决magento后台无法登陆/登陆没有反应的方法
安装过magento的几个版本,安装好后在登陆后台的时候都遇到了点问题,用户名和密码都输入正确,就是登陆不了后台,经过研究发现,登陆不了后台的主要是因为magento自身缓存设置的问题,最模板解决方法 ...
- magento
打开 magento/app/code/core/Mage/Core/Model/Session/Abstract/varien.php//if (isset($cookieParams['doma ...
- magento启用SSL改http成https
Magento是电子商务网站,对于网站的用户信息安全来说,让Magento使用SSL连接是一个很好的解决方案.如果在页面的边栏或者底部放上些表明本站使用安全连接的图片,显得更专业,让客户有安全感,对于 ...
- Magento获取当前页面URL地址
Magento获取当前页面URL地址 http://www.sunhaibing.com/?p=1260 在Magento中,可以通过core/url助手类中的getCurrentUrl()方法获取当 ...
- 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 ...
- 用facebook账号登陆到你的Magento网店
Inchoo提供magento和facebook连接的扩展,可以到http://inchoo.net/ecommerce/magento/facebook-connect-magento-extens ...
- magento后台登陆被锁定 索引报错的解决:General error: 1205 Lock wait timeout
1. magento在索引的时候用shell,有时候会报错: General error: 1205 Lock wait timeout exceeded 这个时候,是因为行锁的原因,在表中您直接用s ...
- Magento在IE下登陆不了后台,在Firefox下正常
目前的解决办法如下: 方法一,用FF登陆后台,在 System—Configuration-Web-Session Cookie management....timeout 改为:86400 方法二: ...
- magento后台无法登陆的问题
解决方法: 打开 magento/app/code/core/Mage/Core/Model/Session/Abstract/varien.php 将// set session cookie pa ...
随机推荐
- WPF装饰元素
Border: <Style TargetType="Border"> <Setter Property="CornerRadius" Val ...
- Redis 操作数据
展现最新数据 Web应用常常要展现最新数据,就会根据时间对数据排序: SELECT * FROM foo WHERE ... ORDER BY time DESC LIMIT 10 随着数据的增加,问 ...
- 【高德地图Android SDK】视频教学
前两天参加了高德在北航举办的公开课,感觉非常不错.完成老师布置的作业之后,还顺利地拿到了高德开发者认证证书!! 现在来跟大家分享一下,如何快速学习[高德地图Android SDK]的开发.一天包会!连 ...
- 微信小程序 - 超出文字省略组件
使用说明 sty:定义样式 text:文字 clamp: 0:代表不限制 1:超过1行省略号(默认) n:超过n行省略 点击下载:ellipsis
- MySql 常见错误代码大全
B.. 服务器错误代码和消息 服务器错误信息来自下述源文件: · 错误消息信息列在share/errmsg.txt文件中.“%d”和“%s”分别代表编号和字符串,显示时,它们将被消息值取代. · 错误 ...
- oj
https://github.com/zhblue/hustoj insert into privilege(user_id,rightstr) values('wxy','administrator ...
- JavaScript的valueOf和toString
深度好文 http://www.cnblogs.com/coco1s/p/6509141.html 知识要点 不同对象调用valueOf和toString的顺序不一样 高阶函数的使用,替代for循环 ...
- Aerospike系列:7:数据分布详解
1:Aerospike数据库是Shared-Nothing架构,集群中的每个节点都是相同的,不会出现单点故障. Aerospike有智能分区算法,即把用户输入的key在内部根据RIPEMD-160算法 ...
- 【Zookeeper】源码分析之请求处理链(二)之PrepRequestProcessor
一.前言 前面学习了请求处理链的RequestProcessor父类,接着学习PrepRequestProcessor,其通常是请求处理链的第一个处理器. 二.PrepRequestProcessor ...
- 操作系统动态内存管理——malloc和free的工作机制
动态内存分配 就 是指在程序执行的过程中动态地分配或者回收存储空间的分配内存的方法. malloc()是C语言中动态存储管理 的一组标准库函数之一.其作用是在内存的动态存储区中分配一个长度为size的 ...