Ale*_*lex 10 php session login magento
我已经扩展Mage_Adminhtml_CustomerController了新的操作loginAction,以便能够从管理界面以客户身份登录.
我叫loginById上customer/session,但客户的会话重定向后不会被修改.
有人可以解释原因吗?这应该是一个简单的操作.
我感谢任何帮助.
谢谢!
我创建了一个包含模块所有代码的github-repo:https://github.com/KATT/Magento-CustomerLogin.
一旦这个问题得到解决,它也可能对其他人有用.
嗨,我创建了一种以客户身份登录的方式.通过以下解决方案,您可以在后端的客户网格管理视图中为每个客户获取一个操作:
你必须为前端创建一个控制器并对一个管理块进行类重写,请适应你的情况,不要忘记创建一个xml文件,在app/etc/modules/Yourmodule_Customer.xml上激活你的模块这里是您必须创建的模块的config.xml:
<?xml version="1.0"?>
<config>
<modules>
<Yourmodule_Customer>
<version>0.1.0</version>
</Yourmodule_Customer>
</modules>
<global>
<blocks>
<adminhtml>
<rewrite>
<customer_grid>Yourmodule_Customer_Block_Adminhtml_Overwrite_Grid</customer_grid>
</rewrite>
</adminhtml>
</global>
<frontend>
<routers>
<customer>
<args>
<modules>
<customer before="Mage_Customer">Yourmodule_Customer_Overwrite</customer>
</modules>
</args>
</customer>
</routers>
</frontend>
Run Code Online (Sandbox Code Playgroud)
然后,您必须在文件夹Youmodule/Customer/Block/Adminhtml/Overwrite/Grid.php中创建一个块类,其中包含以下内容:请注意,如果您在URL中激活了商店代码,则需要在此提供默认商店代码.
<?php
class Yourmodule_Customer_Block_Adminhtml_Overwrite_Grid extends Mage_Adminhtml_Block_Customer_Grid
{
protected function _prepareColumns()
{
parent::_prepareColumns();
$column = $this->getColumn('action');
$actions = $column->getActions();
$actions[] = array(
'caption' => 'Log in',
'popup' => true,
'url' => array(
'base' => 'customer/support/autologin',
'params' => array('_store' => 'de', '_secure' => true)),
'field' => 'customerid'
);
$column->setActions( $actions );
return $this;
}
}
Run Code Online (Sandbox Code Playgroud)
然后你必须创建一个新的前端控制器,在这种情况下,它只限于在后端配置中定义的授权IP地址:
<?php
class Yourmodule_Customer_Overwrite_SupportController extends Mage_Core_Controller_Front_Action
{
public function preDispatch(){
parent::preDispatch();
if (!$this->getRequest()->isDispatched()) {
return;
}
$action = $this->getRequest()->getActionName();
$pattern = '/^(autologin)/i';
if (!preg_match($pattern, $action) && Mage::helper('core')->isDevAllowed(Mage::app()->getStore()->getId())) {
if (!$this->_getSession()->authenticate($this)) {
$this->setFlag('', 'no-dispatch', true);
}
} else {
$this->_getSession()->setNoReferer(true);
}
}
public function autologinAction(){
$session = $this->_getSession();
$id = (int) trim($this->getRequest()->getParam('customerid'));
try{
if($id){
$customer = Mage::getModel('customer/customer')->load($id);
$session->setCustomerAsLoggedIn($customer);
$message = $this->__('You are now logged in as %s', $customer->getName());
$session->addNotice($message);
Mage::log($message);
}else{
throw new Exception ($this->__('Auto Loggin didn\'t worked. Some parameter are missing'));
}
}catch (Exception $e){
$session->addError($e->getMessage());
}
$this->_redirect('customer/account');
}
public function _getSession(){
return Mage::getSingleton('customer/session');
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6236 次 |
| 最近记录: |