Ich bin hier verfügbaren Add new action
aufAccountController
Jetzt: AccountController wird ordnungsgemäß überschrieben
Aber es ist wann immer hit new Action (ajaxLoginPostAction) is redirect to 302.
Ich füge ajaxLoginPost () als offene Aktion in der Funktion preDispatch () hinzu , abertill is not works.
Hier config.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!--
@author Amit Bera
-->
<config>
<modules>
<Bluehorse_Ajaxlogin>
<version>1.0.0</version>
</Bluehorse_Ajaxlogin>
</modules>
<!-- rewrite Accont Controller -->
<frontend>
<routers>
<customer>
<args>
<modules>
<ajaxlogin before="Mage_Customer">Bluehorse_Ajaxlogin</ajaxlogin>
</modules>
</args>
</customer>
</routers>
<layout>
<updates>
<ajaxlogin>
<file>ajaxlogin.xml</file>
</ajaxlogin>
</updates>
</layout>
</frontend>
<global>
<blocks>
<ajaxlogin>
<class>Bluehorse_Ajaxlogin_Block</class>
</ajaxlogin>
</blocks>
<helpers>
<ajaxlogin>
<class>Bluehorse_Ajaxlogin_Helper</class>
</ajaxlogin>
</helpers>
</global>
</config>
AccountController.php
<?php
/* @ Purpose ajax login
* @ Author Amit Bera<[email protected]>
* @ Module Bluehorse_Ajaxlogin
*/
require_once Mage::getModuleDir('controllers', 'Mage_Customer').DS.'AccountController.php';
class Bluehorse_Ajaxlogin_AccountController extends Mage_Customer_AccountController{
/* Add new Action
*/
protected $_cookieCheckActions = array('loginPost', 'createpost','ajaxLoginPost');
protected $defaultOpenActionList=
array(
'create',
'login',
'logoutsuccess',
'forgotpassword',
'forgotpasswordpost',
'resetpassword',
'resetpasswordpost',
'confirm',
'confirmation',
'loginPost',
'createpost'
);
protected $newOpenActionList= array(
'ajaxloginPost'
);
/* Check customer authentication for some actions */
public function preDispatch() {
$currenAction=$this->getRequest()->getActionName();
$pattern = '/^(' . implode('|', $this->newOpenActionList) . ')/i';
if (preg_match($pattern, $currenAction)):
$TempAction= $this->getRequest()->setActionName('index');
endif;
parent::preDispatch();
if($currenAction!=$this->getRequest()->getActionName()){
$this->getRequest()->setActionName($currenAction);
}
if(!$this->getRequest()->isDispatched()){
return;
}
if (!preg_match('/^('.$this->_getValidActions().')/i', $currenAction)) {
if (!$this->_getSession()->authenticate($this)) {
$this->setFlag('', 'no-dispatch', true);
}
} else {
$this->_getSession()->setNoReferer(true);
}
}
protected function _getValidActions(){
return implode("|", array_merge($this->defaultOpenActionList, $this->newOpenActionList));
}
public function ajaxLoginPostAction(){
$result = array();
if (!$this->_validateFormKey()) {
$result['success'] = 0;
$result['error'] = $this->_getHelper('customer')->__('Invalid form key.');
Mage::throwException('Invalid form key');
return;
}
if ($this->_getSession()->isLoggedIn()) {
$this->_redirect('*/*/');
return;
}
$session = $this->_getSession();
if ($this->getRequest()->isPost()) {
$login = $this->getRequest()->getPost('login');
if (!empty($login['username']) && !empty($login['password'])) {
try {
$session->login($login['username'], $login['password']);
if ($session->getCustomer()->getIsJustConfirmed()) {
$result=$this->_AjaxwelcomeCustomer($session->getCustomer(), true);
}
} catch (Mage_Core_Exception $e) {
switch ($e->getCode()) {
case Mage_Customer_Model_Customer::EXCEPTION_EMAIL_NOT_CONFIRMED:
$value = $this->_getHelper('customer')->getEmailConfirmationUrl($login['username']);
$message = $this->_getHelper('customer')->__('This account is not confirmed. <a href="%s">Click here</a> to resend confirmation email.', $value);
break;
case Mage_Customer_Model_Customer::EXCEPTION_INVALID_EMAIL_OR_PASSWORD:
$message = $e->getMessage();
break;
default:
$message = $e->getMessage();
}
$session->setUsername($login['username']);
$result['success'] = 0;
$result['error'] =$message;
} catch (Exception $e) {
// Mage::logException($e); // PA DSS violation: this exception log can disclose customer password
$result['success'] = 0;
$result['error'] =$e->getMessage();
}
} else {
$result['success'] = 0;
$result['error'] =$this->__('Login and password are required.');
}
}
$this->getResponse()->setHeader('Content-type', 'application/json');
$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
}
protected function _AjaxwelcomeCustomer(Mage_Customer_Model_Customer $customer, $isJustConfirmed = false)
{
$result=array();
$result['success'] = 1;
$result['message'] = $this->__('Thank you for registering with %s.', Mage::app()->getStore()->getFrontendName());
if ($this->_isVatValidationEnabled()) {
// Show corresponding VAT message to customer
$configAddressType = $this->_getHelper('customer/address')->getTaxCalculationAddressType();
$userPrompt = '';
switch ($configAddressType) {
case Mage_Customer_Model_Address_Abstract::TYPE_SHIPPING:
$userPrompt = $this->__('If you are a registered VAT customer, please click <a href="%s">here</a> to enter you shipping address for proper VAT calculation',
$this->_getUrl('customer/address/edit'));
break;
default:
$userPrompt = $this->__('If you are a registered VAT customer, please click <a href="%s">here</a> to enter you billing address for proper VAT calculation',
$this->_getUrl('customer/address/edit'));
}
$result['success'] = 1;
$result['message'] = $userPrompt;
}
$customer->sendNewAccountEmail(
$isJustConfirmed ? 'confirmed' : 'registered',
'',
Mage::app()->getStore()->getId()
);
return $result;
}
}
Ich kann das Problem nicht finden.
Kann jemand eine Lösung haben
Aktualisieren:
$ this-> getResponse () -> setBody (Mage :: helper ('core') -> jsonEncode ($ result))
Weiterleitung zum Kunden / Konto / Login mit 302
quelle
if (preg_match($pattern, $currenAction)): $TempAction= $this->getRequest()->setActionName('login'); endif;
parent::preDispatch();
dankeHeader zurücksetzen
Ich habe die Lösung gefunden, indem ich den Inhaltstyp der Header-Antwort geändert habe.
$this->getResponse()->clearHeaders()
content type
-> einapplication/json
Ändern Sie also das Tun von:
zu
Und geben Sie 302-Umleitung mit den erforderlichen Ergebnis-JSON-Daten.
Folgen:
Antwort von Alan Storm: https://stackoverflow.com/a/4442879/2940291
& @philwinkle https://magento.stackexchange.com/a/16238
Ich habe die Idee von ihnen bekommen
302-Weiterleitung anzeigen:
Nach dem Hinzufügen zeigt es die 302-Umleitung an, aber es gibt JSON-Daten, wie ich will.
Noch 302 Header-Umleitung mit korrekter Rückgabe.
Lösung:
Jetzt erinnert, dass ich gesetzt habe
indexAction as temp action
fürajaxloginPostAction()
. Das kann ein Problem sein.Und es ist hat right.I Änderung es
loginAction
das istopen action
inMage_Customer_AccountController und mein Override-Controller Bluehorse_Ajaxlogin_AccountController
Wechseln Sie jetzt zu
zu
quelle