I want to programmatically register a user for magento admin. The admin page is in an iframe and should automatically be redirected to the admin control panel without authentication. I used the code found in an ancient post and it matches the magento core source. Code:
umask(0);
$app = Mage::app('default');
Mage::getSingleton('core/session', array('name' => 'adminhtml'));
$user = Mage::getModel('core/factory')->getModel('admin/user')->loadByUsername($loginadmin);
if (Mage::getSingleton('adminhtml/url')->useSecretKey()) {
Mage::getSingleton('adminhtml/url')->renewSecretUrls();
}
$session = Mage::getSingleton('admin/session');
$session->setIsFirstVisit(false);
$session->setUser($user);
$session->setAcl(Mage::getResourceModel('admin/acl')->loadAcl());
Mage::dispatchEvent('admin_session_user_login_success',array('user'=>$user));
if ($session->isLoggedIn()) {
$url = "index.php/admico/dashboard";
header('Location: '.$url);
}
When I have var_dump()data, the user exists and has all the information, such as firstname, id, etc., and all this is correct. The code is included in the latter ifand redirected to "index.php / admico / dashboard", therefore it is $sessioncorrectly registered. But in any case, the connection form is displayed on the first page, as if the session was not registered and not the admin control panel.
- , ?