2016-11-20 1 views
0
내가 로그인에 대한 리디렉션을 설정하고 로그 아웃하는 인증 구성 요소를 사용하고

:CakePHP의 3.x를

$this->loadComponent('Auth', [ 
      'loginRedirect' => [ 
       'controller' => 'Adresses', 
       'action' => 'index' 
      ], 
      'logoutRedirect' => [ 
       'controller' => 'Pages', 
       'action' => 'display', 
       'home' 
      ], 
       'authenticate' => [ 
        'Form' => [ 
         'fields' => ['username' => 'email'] 
        ] 
       ], 
      'authorize' => 'Controller', 

     ]); 

가 지금은 사용자가 얻을 서로 다른 페이지에 따라에 리디렉션 할 물론 지금까지 작동 역할 :

if ($this->Auth->user('role') == 'admin') {       
          return $this->redirect([ 
           'controller' => 'adresses', 
           'action' => 'adminindex' 
          ]); 
         } 
        } elseif ($this->Auth->user('role') == 'user') { 
         return $this->redirect([ 
          'controller' => 'adresses', 
          'action' => 'index' 
         ]); 
        } 

지금 나는 그것을 위해 내가 사용하고 요청 된 links.And에 다른 역할을 리디렉션 할 :

return $this->redirect($this->Auth->redirectUrl()); 
,

보기 및 수정과 같은 요청에 대해서만 작동합니다. 그렇지 않은 경우 원하지 않는 인증 구성 요소 리디렉션으로 되돌아갑니다.

보기가 요청되고 사용자/관리자가 이미 로그인되어있는 경우 인증 구성 요소 (App Controller)의 내 역할 전환기와 리디렉션에서 내 정기 폴백을 수행하려면 어떻게해야합니까? 이를 위해

내가 시도 :

if(!empty($this->Auth->redirectUrl())){ 

} 

working.Any 생각은 감사하겠습니다하지 않는.

답변

2
$this->Auth->redirectUrl() 

는 로그인

http://book.cakephp.org/3.0/en/controllers/components/authentication.html#redirecting-users-after-login

를 참조하면 리퍼러 페이지로 리디렉션해야하는 경우가 Controller::referer()

볼 수 있습니다 후 단지에 대한 리디렉션 사용자입니다 http://api.cakephp.org/3.3/class-Cake.Controller.Controller.html#_referer

당신이 할 수있는 로그인 한 사용자를로 확인하십시오.

+0

고마워요! 매력처럼 작동합니다 (http://book.cakephp.org/3.0/en/controllers.html#redirecting-to-other-pages). – Isengo