2017-04-10 110 views
0

我知道一個成功的用戶登錄後,我可以做一個重定向到URL:重定向到一個路由的用戶登錄後

return $this->redirect()->toUrl('/user/login?redirect=http://www.myurl.com'); 

現在,我願意做同樣的事情,而不是註冊的路線:

'sso-post-login' => array(
    'type' => 'Zend\Mvc\Router\Http\Literal', 
    'options' => array(
     'route' => '/sso-post-login', 
     'defaults' => array(
      'controller' => 'Application\Controller\Index', 
      'action'  => 'sso-post-login', 
     ), 
    'may_terminate' => true, 
    ), 
), 

但下面不工作:

return $this->redirect()->toUrl('/user/login?redirect=/sso-post-login'); 

它不打我的行動:

public function ssoPostLoginAction() { 
    error_log("In sso post login action"); 
    $originUrl = Common::getCookie('sso_post_login', $this->getRequest()); 
    $sessionCookie = Common::getCookie('PHPSESSID', $this->getRequest()); 
    if (null != $sessionCookie && null != $this->getUserService()->getAuthService()->getIdentity()) { 
     $email = $this->getUserService()->getAuthService()->getIdentity()->getEmail(); 
     $jwtCredentials = $this->buildJWTLoginToken($email); 
     $originUrl .= "?jwt=" . $jwtCredentials; 
     return $this->redirect()->toUrl($originUrl); 
    } 
} 

它只是在登錄完成後重定向到主頁面。

回答

2

是否有具體的原因,你不想把完整的(絕對)網址到redirect param? 你可以這樣做:

return $this->redirect()->toUrl("/user/login?redirect=".$this->url()->fromRoute('sso-post-login', [], ['force_canonical' => true])); 

force_canonical選項將生成完整的URL(包括主機名)

+0

沒有,沒有任何理由,我很樂意使用,將工作的任何解決方案。我試過你的解決方案,但它重定向到主頁面,而不是重定向到'sso-post-login'。 – Stephane

+1

您確定您可以在瀏覽器中訪問「http:// www.myurl.com/sso-post-login」嗎?它不會拋出任何錯誤或重定向到主頁面嗎? – SzymonM

+0

確實,就是這樣。我忘了將它再次添加到'bjyauthorize.php'文件中。 – Stephane