我是一个初学者 zend 框架程序员。我确实使用 ZfcUser 进行身份验证,使用 Bjyauthorize 进行授权。我要用户类型:普通用户和管理员。所以我想做的是在认证后将用户路由到页面 A 和管理员到页面 B。在 Zfcuser 配置文件中没有这种可能性,我们只有这一行
'logout_redirect_route' => 'zfcuser/login',
如何为我的不同用户指定不同的路线?
我是一个初学者 zend 框架程序员。我确实使用 ZfcUser 进行身份验证,使用 Bjyauthorize 进行授权。我要用户类型:普通用户和管理员。所以我想做的是在认证后将用户路由到页面 A 和管理员到页面 B。在 Zfcuser 配置文件中没有这种可能性,我们只有这一行
'logout_redirect_route' => 'zfcuser/login',
如何为我的不同用户指定不同的路线?
对我来说,您的问题与 ZfcUser 或 BjyAuthorize 无关:只需让用户和管理员进入您的控制器,然后您就可以根据用户角色来调度它们。
return $this->forward()->dispatch('MyModule\Controller\Index', array('action'=>'PageB'));
假设您在 bjyauthorize 中有一个“管理员”角色,您想重定向到另一个路由。
在您的 loginAction 中替换代码:
if ($this->zfcUserAuthentication()->getAuthService()->hasIdentity()) {
return $this->redirect()->toRoute($this->getOptions()->getLoginRedirectRoute());
}
使用此代码:
if ($this->zfcUserAuthentication()->getAuthService()->hasIdentity()) {
$roles = $this->serviceLocator->get('BjyAuthorize\Provider\Identity\ProviderInterface')->getIdentityRoles();
if (in_array('admin',$roles))
{
return $this->redirect()->toRoute('admin_route');
} else {
return $this->redirect()->toRoute('user_route');
}
}