繁体   English   中英

用户登录后重定向到路由

[英]Redirect to a route after user login

我知道我可以在成功登录用户后重定向到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);
    }
}

登录完成后,它只是重定向到主页。

您是否有特定原因不想让完整(绝对)URL redirect参数? 您可以这样做:

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

force_canonical选项将生成完整的URL(包括您的主机名)

暂无
暂无

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

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