Question

I want to do auto login of some customer to admin as admin user.
They have a link in their account dashboard , which will do auto login.
Till now have implemented to sync customer details with admin user account, so manually one can login into admin with customer mail and their id as password.
However now I am stuck with how to implement it by just clicking on the link.

Any help highly appreciated.

Was it helpful?

Solution

Considering that you have registered customer as admin user and now you have admin username. Esest way to make him autologin will be by creating a file in magento root lets say autologin.php and Now int this file first of all get user

require_once 'app/Mage.php';
umask(0);
$app = Mage::app('default');
Mage::getSingleton('core/session', array('name' => 'adminhtml'));
$username = $_POST['username'];
$user = Mage::getModel('admin/user')->loadByUsername($username);

then initiate secrete key

if (Mage::getSingleton('adminhtml/url')->useSecretKey()) {
  Mage::getSingleton('adminhtml/url')->renewSecretUrls();
}

logging in and setting up session

$session = Mage::getSingleton('admin/session');
$session->setIsFirstVisit(true);
$session->setUser($user);
$session->setAcl(Mage::getResourceModel('admin/acl')->loadAcl());
Mage::dispatchEvent('admin_session_user_login_success',array('user'=>$user));

Finally redirect to whatever url you like

//$url = Mage::helper("adminhtml")->getUrl("acompany_mymodule/index/index");
$url = Mage::getUrl('adminhtml/*/*');
$url = str_replace('autologin.php', 'index.php', $url);
header('Location:  '.$url);
exit();

So now can create a button anywhere which submits a form to this url BASE_URL/autologin.php with username in post request

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top