I'm getting started with CakePHP and I'm having a problem setting up the Auth component. Every time a user logs out, cake is redirecting them back to login. You will see that I'm trying to delete/unset some cookies during logout(). This is because I'm setting up a single sign on with a Wordpress site, so I want the user to be logged out of both sites.
My AppController:
class AppController extends Controller {
public $components = array(
'Session',
'Cookie',
'Auth' => array(
'loginRedirect' => array('controller' => 'questions', 'action' => 'index'),
'logoutRedirect' => array('controller' => 'pages', 'action' => 'display', 'home')
)
);
public function beforeFilter() {
$this->Auth->allow('index', 'view', 'login', 'logout', 'display');
}
}
UsersController:
class UsersController extends AppController {
public function beforeFilter() {
parent::beforeFilter();
$this->Auth->allow('add', 'logout', 'login');
}
...
public function login() {
//who cares
}
public function logout() {
$wp_cookie = grab_wp_cookie(); //this grabs a specific cookie
$cookie_name = (isset($wp_cookie['name'])) ? $wp_cookie['name'] : NULL;
//NONE OF THESE WORK...
$this->Cookie->write($cookie_name, '', false, time()-3600);
$this->Cookie->delete($cookie_name);
$this->Cookie->destroy();
$this->redirect($this->Auth->logout());
}
It seems you don't have access to the page without being logged. (you can try it accessing to the URL without being logged just to check it)
The solution is to add this beforeFilter
function at your PagesController:
public function beforeFilter(){
parent::beforeFilter();
$this->Auth->allow();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With