Using magento 2
. I want to allow a user customer use only one device at the same time. Example It look like admin login, admin cannot login to other device while they login current device.
2 Answers
There is a section "Online Customers" under Customers in Admin.
Here magento shows name, email, ip address, session start time, last activity and last url accessed.
you can call 'Magento\Customer\Model\Visitor' model and get list of all currently online customers/ visitors.
Now whenever a customer logs in, you can make a custom observer and call its function to match email of that customer with all this data you got from model.
and logout cutomer from previous device if you find a record same.
Hope it helps.
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;
}