2
require_once 'mystore/app/Mage.php';
 umask(0);
 Mage::app('default'); 
Mage::getSingleton('core/session', array('name' => 'adminhtml'));
$user = Mage::getModel('admin/user')->loadByUsername('admin');
if (Mage::getSingleton('adminhtml/url')->useSecretKey()) {
Mage::getSingleton('adminhtml/url')->renewSecretUrls();
}

$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));

if ($session->isLoggedIn()) {
  echo "Logged in";
  $redirectUrl = Mage::getSingleton('adminhtml/url')->getUrl(Mage::getModel('admin/user')->getStartupPageUrl(), array('_current' => false));
  header('Location: ' . $redirectUrl);
    exit;
}

It is redirecting to the admin panel but shows the login page. Is it possible show the dashboard as the admin is already logged in?

0

I will not get into how much of a security hole this code would expose. I am sure that you know what you are doing.

First of all, you are loading up the "default" store. You should be loading the "admin" store Mage::app(0) or Mage::app('admin').

I don't understand what you are doing with line 4 of your code... you should probably just use:

$session = Mage::getSingleton('admin/session');

// don't mess with the existing admin session
if ($session->isLoggedIn()) {
    $session->refreshAcl();

    // redirect has to go somewhere... 
    Mage::app()->getResponse()->setRedirect(Mage::helper('adminhtml')->getUrl('adminhtml/dashboard/'));
} else {
    // continue on with login code here
}

The Magento Admin login code is handled in:

Mage_Admin_Model_Observer::actionPreDispatchAdmin()
  • I installed manthan extension for multi vendor store.I am trying to login to the vendor panel from the frontend.Your suggestion returns the same result as it is not redirecting to the dashboard and stays in the login page.Do you have any suggestion? – Rose Dec 13 '16 at 6:04
  • The example code was not complete, and I am not familiar with the manthan extension. – Phil M Dec 13 '16 at 16:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.