Zend Framework2 using Zfcuser & Bjyauthorize routing

只愿长相守 提交于 2019-12-11 20:34:37

问题


I'm a beginer zend framework programmer. I did use ZfcUser for authentification and Bjyauthorize for authorization. I have to type of users : normal users and administrator . So what i want to do is to route the user to page A and admin to page B after authentification . In the Zfcuser configuation file there not this possibility we have just this line

 'logout_redirect_route' => 'zfcuser/login',

how can do specify a diffrent route for my differents users?


回答1:


To me your problem has nothing to do with ZfcUser or BjyAuthorize: Just let the user and the admin go inside your controller and there you can dispatch them depending on the user role.

return $this->forward()->dispatch('MyModule\Controller\Index', array('action'=>'PageB'));



回答2:


Suppose you have an 'admin' role in bjyauthorize that you want to redirect to another route.

In your loginAction replace the code:

    if ($this->zfcUserAuthentication()->getAuthService()->hasIdentity()) {
        return $this->redirect()->toRoute($this->getOptions()->getLoginRedirectRoute());
    }

with this code:

    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');
        }
    }


来源:https://stackoverflow.com/questions/16674060/zend-framework2-using-zfcuser-bjyauthorize-routing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!