2013-04-17 5 views
1

내 프로젝트에서 ZfcUser 및 BjyAuthorize를 사용하고 있습니다. 사용자가 로그인하면 내 기본 경로로 리디렉션됩니다.ZfcUser 로그인 후 다른 페이지로 역할 리디렉션

하지만 난 역할 A를 사용자가 페이지 A로 리디렉션하고 역할 B와 사용자가 페이지 B.

어떤 생각으로 리디렉션됩니다, 그래서 만약을 변경하려면, 어떻게 실현 하는가?

+1

당신은'UserController # authenticateAction()'을 덮어 써야 할 것이다. 이것은 또한 호출 할 수있는'zfcuser'를 당신의 컨트롤러에 덮어 쓸 것을 요구한다. 잡힌 점은 모듈의 뷰 템플릿도 제공해야한다는 것입니다.) 매우 까다 롭고 솔직히 ZfcUser가 다시 작성해야 할 수도 있습니다. D – Sam

+0

감사합니다. 새로운 Action을 추가하기 위해 이미'UserController'를 덮어 썼습니다. 그러나 나는 해결책에 대한 당신의 제안으로 내 문제를 해결하려고 노력합니다. – KFO

+0

페이지에 가입 할 때 리디렉션하여 (일부 작업 처리) 올바른 사용자 페이지로 리디렉션하려고 할 수 있습니다 (역할에 따라) –

답변

1

실제로 이것을 수행하고 GitHub에서 병합 요청을 만들었습니다. 실제로는 zfc-user/src/ZfcUser/Controlelr/UserController.php에서 수행해야하는 아주 작은 변경 사항입니다. authenticateAction() 내에서이를 교체해야이 들어

return $this->redirect()->toRoute($this->getOptions()->getLoginRedirectRoute()); 

:

$route = $this->getOptions()->getLoginRedirectRoute(); 

if(is_callable($route)) { 
    $route = $route($this->zfcUserAuthentication()->getIdentity()); 
} 

return $this->redirect()->toRoute($route); 

그리고 당신이 사용할 수 있습니다 귀하의 설정/자동로드/module.zfcuser.global.php 파일에

login_redirect_route에 대한 콜백 :

사용자 한번 기록됩니다 (기본 경로 loggin에 후) 및 역할에 따라보다 내가 간단한 모듈을 생성했습니다 역할에 따라 몇 가지를 확인해야으로
'login_redirect_route' => function(\ZfcUser\Entity\UserInterface $user) { 
    if($user->getUsername()=='Admin') { 
     return 'admin'; 
    } 

    return 'user'; 
} 
+0

안녕하세요 마크, 위의 설명에서 보셨 듯이 이미 문제를 해결했습니다. 'UserController :: authenticateAction()'을 덮어 쓰면된다. 그러나 귀하의 솔루션은 좋은 접근 방법입니다. – KFO

1

(사용 가능한 throu gh bjyautorize)는 응용 프로그램을 해당 URL로 리디렉션합니다.

아마도 우아한 방법은 아니지만 zfc 사용자 코드를 수정할 필요는 없습니다.

0

다른 경로로 리디렉션하려는 bjyauthorize의 'admin'역할이 있다고 가정합니다. 이 코드

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

: 당신의 loginAction에서

코드를 대체 당신은 config 파일에서 로그인 후 설정을 재 지정할 수 있습니다

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

.

'login_redirect_route' => '/your-url', 

사용자의 모든 유형에서 액세스 할 수 your-url 다음 스위치 케이스를 만들 수는 역할과 일치하는 역할 특정 페이지로 페이지를 리디렉션합니다.

$roles = $this->serviceLocator->get('BjyAuthorize\Provider\Identity\ProviderInterface')->getIdentityRoles(); 


switch ($roles){ 

    case "admin": 
      $this->redirect()->toRoute('user_admin'); 
    case "user":    
      $this->redirect()->toUri('user.html'); 
} 
관련 문제