2012-09-17 2 views
0

, 나는 domain.com을 가지고 있지만 나는 (URL을 domain.com/logout 입니다) 로그 아웃 할 때, 그것은 domain.com/app/login 로 리디렉션됩니다 리디렉션합니다. domain.com/app/login으로 리디렉션하지 않고 대신 domain.com/logout으로 리디렉션하고 싶습니다. 이들은 어떤 도움이 좋을 것CakePHP의 - 인증 로그 아웃은 cakephp2.0에서

class UsersController extends AppController { 
public $components = array(

    'Auth' => array(
     'loginRedirect' => array('controller' => 'posts', 'action' => 'index'), 
     'logoutRedirect' => array('controller' => 'users', 'action' => 'login'), 
     'authorize' => array('Controller') // Added this line 
    ) 
); 

public function beforeFilter() { 
    parent::beforeFilter(); 
    $this->Auth->allow('add', 'logout', 'login'); 
    $this->Auth->deny('view'); 
} 

public function login() { 
    if ($this->request->is('post')) { 
     if ($this->Auth->login()) { 

      $this->redirect('http://domain.com/thankyou'); 
     } else { 
      $this->Session->setFlash(__('Invalid username or password, try again')); 
     } 
    } 
} 

public function logout() { 
    $this->redirect($this->Auth->logout()); 
} 
} 

내 UsersController & 내 AppController가

class AppController extends Controller { 
public $helpers = array ('Html', 'Form', 'Js' => array('Jquery'), 'Session'); 

public $components = array(
    'Session', 
    'Auth' => array(
     'loginRedirect' => array('controller' => 'posts', 'action' => 'index'), 
     'logoutRedirect' => array('controller' => 'users', 'action' => 'login'), 
     'authorize' => array('Controller') // Added this line 
    ) 
); 
} 

Userscontroller에 내가 가지고있는 코드이다. 감사.

답변

5

잊지 마세요() 함수

$this->Auth->logout() 
$this->redirect(some url); 
2

로그 아웃 페이지에 대한보기가 있습니까? 로그 아웃 한 후에 표시하려고하는 것이 있습니까? 어떤 일이 벌어 질지는 사용자가 로그 아웃되었지만 Cake가 안전하기 때문에 Cake가 로그 아웃 페이지를 표시 할 수 없으므로 Cake는 로그인 페이지로 리다이렉트합니다.

보안이 사용하고 원하는 페이지가 로그인하지 않은 사용자에게 표시하는 경우는 컨트롤러에서이 같은 것을 포함해야합니다

public function beforeFilter() { 
    parent::beforeFilter(); 
    $this->Auth->allow('login','logout'); 
} 
1

당신이 그것을 확인 했나를?

'Auth' => array(
    'loginRedirect' => array('controller' => 'posts', 'action' => 'index'), 
    'logoutRedirect' => array('controller' => 'users', 'action' => 'login'), 
) 

그리고 당신의 rootes에서 다음

public function logout() { 
    //$this->redirect($this->Auth->logout()); 
    //Change for : 
    //I suppose that you have a logout.ctp view in your View/Pages 
    $this->redirect(array('controller' => 'pages', 'action' => 'display', 'logout') 
} 

물론

Router::connect('/logout', array('controller' => 'pages', 'action' => 'display', 'logout')); 

내가 내 로그 아웃이를 사용하여 종료

$this->Auth->allow('display' 
관련 문제