2017-05-24 4 views
1

최근에 cakephp 3.3.4를 cakephp 3.4.7로 업그레이드했습니다. 이전 버전에서는 현재 페이지에 로그인 한 상태에서 현재 페이지로 리디렉션하고 있지만 업그레이드 한 후에는 홈 페이지로 리디렉션하면 문제가 무엇인지 알 수 없습니다.cakephp를 사용하여 로그인 한 후 현재 페이지로 리디렉션 3.4.7

public function login() 
{ 
    if($this->Auth->user()){ 
     $this->Flash->error(__('You are already logged in!')); 
     return $this->redirect($this->Auth->redirectUrl()); 
    } 
    else{ 
     if ($this->request->is('post')) { 
     $user = $this->Auth->identify(); 
     if ($user) { 
      $this->Auth->setUser($user); 
      return $this->redirect($this->Auth->redirectUrl()); 
     } 
     $this->Flash->error('Your username or password is incorrect.'); 
     } 
    } 
} 

답변

0

리디렉션 현재 페이지 : 아무도

public function initialize() 
{ 
    parent::initialize(); 

    $this->loadComponent('RequestHandler'); 
    $this->loadComponent('Flash'); 
    $this->loadComponent('Auth', [ 
     'authorize' => ['Controller'], 
     'authenticate' => [ 
      'Form' => [ 
       'fields' => [ 
        'username' => 'email', 
        'password' => 'password' 
       ], 
       'scope' => ['userStatus' => '1'] 
      ] 
     ], 
     'loginAction' => [ 
      'controller' => 'Users', 
      'action' => 'login' 
     ], 
     'unauthorizedRedirect' => $this->referer(), 
     'logoutRedirect'  => [ 
       'controller' => 'Users', 
       'action'  => 'login' 

     ] 
    ]); 
} 

로그인 기능 여기에 저를 도와주세요

if ($this->request->is('post')) { 
    if ($this->Auth->login()) { 
     $this->redirect($this->Auth->redirectUrl()); 
    } else { 
     $this->Flash->error(__('Your username or password is incorrect.')); 
    } 
} 

당신이 로그인의 특정 위치로 리디렉션하려는 경우, 확인 AppController에서 Auth Component를 초기화 할 때 loginRedirect를 설정했는지 확인하십시오.

public function initialize() 
{ 
    parent::initialize(); 

    $this->loadComponent('Flash'); 
    $this->loadComponent('Auth', [ 
     'authenticate' => [ 
      'Form' => [ 
       'fields' => [ 
        'username' => 'email', 
        'password' => 'password' 
       ] 
      ] 
     ], 
     'loginAction' => [ 
      'controller' => 'Users', 
      'action' => 'login', 
      'prefix' => false 
     ], 
     'unauthorizedRedirect' => $this->referer(), 
     /* You need this part */ 
     'loginRedirect' => [ 
      'controller' => 'dashboard', 
      'action' => 'index' 
     ] 
    ]); 

} 

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

+0

안녕, 당신이 게시 된 내가 사용하지만, 여전히 홈 페이지에만 리디렉션합니다. 질문에서 내 코드를 볼 수 있습니다. – Ashok

+0

범위와 포함 옵션은 3.1에서 더 이상 사용되지 않습니다. 대신 사용자 정의 찾기를 사용하여 사용자 레코드를 페치하도록 쿼리를 수정하십시오. 로그 아웃 동작에'$ this-> redirect ($ this-> Auth-> redirectUrl()); '를 포함 시켰습니까? $ this-> Auth-> logout()); –

+0

아니요 로그인 기능에 로그 아웃 기능이 있어야합니다.이 리턴 코드를 사용하고 있습니다. $ this-> > redirect ($ this-> Auth-> logout()); – Ashok