문제

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?

도움이 되었습니까?

해결책

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

다른 팁

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');
        }
    }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top