In order to check whether the current user is logged in or not, we can easily find out using the following code:
if(Mage::getSingleton('customer/session')->isLoggedIn()){
//customer is logged in
}
Note
: This code only checks the current session of a customer using current browser.
Case:
Suppose if a user with email: customer@domain.com is already logged
in via one browser, the same user tries to login via another browser or
another user who knows the usename / password tries to login from
another location then how will you check if customer with that email is
already logged in?
Solution:
Well it’s simple enough.
You can create Event/Observer that hook into the event: customer_login and check as follows in the observer method:
$customer = $observer->getEvent()->getCustomer();
$log = Mage::getModel('log/visitor_online')->getCollection()->addFieldToFilter('customer_id', $customer->getId())->getFirstItem();
if($log->getId()){ //current user is already logged in / online from another location
Mage::getSingleton('customer/session')->logout();
$session->addError(Mage::helper('customer')->__('Customer with email (%s) is already logged in.', $customer->getEmail()));
Mage::app()->getResponse()->setRedirect(Mage::getUrl('customer/account/login'));
return;
}
Notes
: If you browse the table: log_visitor_online you
can see it stores the details of currently logged in customers and
guests. Above code just tries to check if current customer details is on
the table or not. If customer data is present it means he/she is
already logged in and online else this will be his/her fresh login.
来源:http://www.blog.magepsycho.com/how-to-check-if-customer-is-already-logged-in-from-another-location/
分享到:
相关推荐
You’ll start by getting a general understanding of what Magento is, why and how you should use it, and whether it is possible and feasible to migrate from an old web store to Magento 2. As you work ...
Chapter 3, Enabling Performance in Magento 2, explains how to configure different types of caching options. In Magento 2, the Full Page Cache (FPC) can be handled by Varnish to give your store a ...
Chapter 3, Enabling Performance in Magento 2, explains how to configure different types of caching options. In Magento 2, the Full Page Cache (FPC) can be handled by Varnish to give your store a ...
magento环境检测
magento入门原版书.。。The Definitive Guide to Magento.pdf
Apress.The.Definitive.Guide.to.Magento.Dec.2009.pdf Apress于2009重磅推出的Magento上手书籍,原书地址:http://www.apress.com/book/view/9781430272298
magento判断用户是否登录和怎么获取登录者名称:
对于首次安装magento过程中出现的问题的小结
magento facebook快捷登陆插件
Understand Magento extensions, and build your own from scratch! Overview Get a detailed insight into the structure of Magento Learn about event/observer-driven modules Get a hands-on introduction to...
magento数据结构分析 magento数据字典
NULL 博文链接:https://justcoding.iteye.com/blog/2100394
magento2-force-login, Magento 2强制登录模块 如果页面没有标记为 visitable,访问者会被重定向到登录页面。 插件功能:在允许访客访问你的网页和目录之前,强制你的访客先登录( 或者 register )管理:管理区域中的...
允许您在客户登录,注销并创建新帐户后重定向到自定义页面。(禁止用作商业用途)
magento用户中文操作手册,学习magento后台管理
magik shoes magento 模板, magento 1.7 模板
magento的SMTP插件magento的SMTP插件magento的SMTP插件
深入理解Magento 由精东博客下载下来制作成pdf
安装扩展程序后,社交登录按钮将显示在帐户登录和注册页面,结帐页面或您网站上的任何其他位置。(禁止用作商业用途)