Magento Remote Admin Login from module

时间:2015-09-01 22:48:50

标签: php magento

I need to make a single sign on system from an external platform to magento.

I created a module in folder /app/code/local/companyname/Sso/controllers/IndexController.php

When I call $session->isLoggedIn() it says that it's true but when we redirect, it goes to admin login screen. I'm using magento 1.9

class Company_Sso_IndexController extends Mage_Core_Controller_Front_Action {
public function IndexAction()
{
    umask(0);
    Mage::app();
    $action = isset($_GET['action']) ? $_GET['action'] : '';
    $code = isset($_GET['code']) ? $_GET['code'] : '';
    $email = 'test';
    $password = 'test';
    Mage::getSingleton('core/session', array(
        'name' => 'adminhtml'
    ));

    // supply username

    $user = Mage::getModel('admin/user')->loadByUsername($email);
    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())
        {
        $redirectUrl = Mage::getSingleton('adminhtml/url')->getUrl(Mage::getModel('admin/user')->getStartupPageUrl() , array(
            '_current' => false
        ));
        entercodehereheader('Location: ' . $redirectUrl);
        exit;
        }
    }
}

0 个答案:

没有答案