简体   繁体   English

magento的自定义管理员登录脚本

[英]Custom admin login script for magento

I have a custom script, and I want to create a kind of single sign on with Magento for this. 我有一个自定义脚本,我想为此使用Magento创建一种单点登录。

I already found code to create a session and login as customer 我已经找到创建会话并以客户身份登录的代码

$session = Mage::getSingleton( 'customer/session' );
try {
    $session->login( $username, $password ); 
....

But using this does not work 但是使用它不起作用

 Mage::getSingleton( 'admin/session' );//adminhtml does also not work

Basically, what I want is this: 基本上,我想要的是:

  • Have users login to Magento admin from custom login page 让用户从自定义登录页面登录到Magento管理员

  • Keep track of their newly created session 跟踪他们的新创建的会话

another option for me would be to have users login to Magento, and if they then go to my script, I will see that the user is logged in as Admin. 对我来说,另一种选择是让用户登录到Magento,如果他们随后转到我的脚本,我将看到该用户以Admin身份登录。 I found code for this, but somehow this does not work if the user first goes to my script. 我找到了用于此的代码,但是如果用户首先进入我的脚本,这在某种程度上是行不通的。 Here is the code: 这是代码:

$session = Mage::getSingleton('core/session', array('name'=>'adminhtml'));
if(Mage::getSingleton('admin/session')->isLoggedIn()){
....

The code above works, if they user FIRSTLY login to magento. 如果他们首先登录magento,则上面的代码有效。 But if they go to my script first, then I see a cookie gets created with name adminhtml by this line of code: 但是,如果他们先进入我的脚本,那么我会看到以下代码行创建了一个名为adminhtml的cookie:

Mage::getSingleton('core/session', array('name'=>'adminhtml'

So if a user logs into Magento after this, and then goes to my script, this cookie still exists, and checking that for logged in returns false, while another sessioncookie with same name is actually logged in. 因此,如果用户在此之后登录到Magento,然后转到我的脚本,则该cookie仍然存在,并且检查是否已登录返回false,而实际上已登录了另一个具有相同名称的sessioncookie。

Help me please! 请帮帮我! Thanks! 谢谢!

Try this 尝试这个

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM