用户登录后重定向到路由
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(包括您的主机名)
我知道我可以在用户成功登录后重定向到 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(包括您的主机名)