[英]Magento API REST customer not redirecting to Authentication Page
我正在嘗試通過客戶帳戶訪問產品。 為此,我使用來自oauth_customer.php magento文檔頁面的示例代碼。
Everything is okay and working fine; but the thing I am facing is that whenever I login as customer after successful login page redirects to the Customer Dashboard instead of redirecting to the Authentication URL.
為此,我必須手動再次粘貼URL鏈接,以便它重定向到“身份驗證”頁面,並且在身份驗證后顯示我想要的內容。
我還嘗試通過以下鏈接的示例代碼擴展帳戶控制器: https : //docs.google.com/file/d/0BzCDl5a0zmSVdWdFMG9jMTB1TXM/edit?pli = 1
但是仍然沒有運氣。 無論如何,是否像我們在管理員身份驗證側一樣在登錄后再次創建回調URL?
最后,我自己找到了解決方案。 我決定在這里發布,這樣可能會對某人有所幫助。 通過遵循以下示例代碼: https://docs.google.com/file/d/0BzCDl5a0zmSVdWdFMG9jMTB1TXM/edit?pli=1
: https://docs.google.com/file/d/0BzCDl5a0zmSVdWdFMG9jMTB1TXM/edit?pli=1
我可以獲取重定向網址。 但是,隨着重定向添加帶有站點URL的重定向鏈接,重定向路徑移至404頁面。 重定向到URL的代碼是$this->_redirectUrl($session->getBeforeAuthUrl(true));
我將此代碼更改為header( "refresh:1;url=".$session->getBeforeAuthUrl(true));
因此,它成功重定向到“授權”頁面。 我認為magento花了幾毫秒來創建它的cookie。 所以我增加了一些刷新時間。 這是AccountController類代碼:{yourmagento} / app /代碼/社區/Chalkfy/OAuthRedirect/controllers/AccountController.php
<?php
require_once 'Mage/Customer/controllers/AccountController.php';
class Chalkfly_OAuthRedirect_AccountController extends Mage_Customer_AccountController {
protected function _loginPostRedirect()
{
$session = $this->_getSession();
// if this redirect is a result of the OAuth process, force the redirect
if(stristr($session->getBeforeAuthUrl(),"oauth/authorize?oauth_token=") == 0 )
{
echo "Redirecting Please Wait..";
// Redirect to the URL after get
header( "refresh:1;url=".$session->getBeforeAuthUrl(true));
// $this->_redirect($session->getBeforeAuthUrl(true));
}
else {
parent::_loginPostRedirect();
}
}
}
使用Oauth時,oauth消費者登錄表單將重定向到customer / account / loginPost。
由於缺少參數formkey,loginPost函數會將您重定向到客戶/帳戶/登錄。
只需在form標簽的末尾添加到app / design / frontend / package / theme / template / oauth / authorize / form / login.phtml中,即可:
<input type="hidden" name="form_key" value="<?php echo Mage::getSingleton('core/session')->getFormKey(); ?>" />
當您添加重定向時,重定向將正常工作。 在Magento CE 1.9.0.0,EE 1.14.1.x中測試
您可以覆蓋控制器或創建觀察者。
這是修復您問題的鏈接: http : //blog.belvg.com/magento-tips-how-to-redirect-a-user-to-other-page-than-his-account-page-after-login -in-magento.html
如bas_van_poppel所說,通過將form鍵添加到適當的phtml中,您可以擺脫對常規登錄頁面的重定向。
為了避免重定向到儀表板頁面並重定向到您的應用程序,您需要在app/code/core/Mage/Oauth/controllers/AuthorizeController.php
上的_initForm
方法中刪除對setAfterAuthUrl
的調用:
/** @var $helper Mage_Core_Helper_Url */
$helper = Mage::helper('core/url');
$session // We don't want this: ->setAfterAuthUrl(Mage::getUrl('customer/account/login', array('_nosid' => true)))
->setBeforeAuthUrl($helper->getCurrentUrl());
成功登錄后,Magento將客戶重定向到客戶會話中的after_auth_url值,如果未指定該值,它將把您重定向到before_auth_url的值。
這僅出於說明目的,您應遵循最佳實踐來覆蓋此核心控制器。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.