0
votes

OK, another one for the cakephp ninjas today.. Here it is : I have a login/logout system implemented.. I am using $components attr in the AppController, and using the Auth config key to set up loginRedirect and logoutRedirect.. The code looks like this :

public $components = array(
    'DebugKit.Toolbar',
    'Session',
    'Auth' => array(
        'loginRedirect' => array(   
            'controller' => 'posts',
            'action' => 'index'
        ),
        'logoutRedirect' => array(  
            'controller' => 'users',
            'action' => 'login'
        ),
        'authorize' => array('Controller') 
    )
);

The logout action looks like this :

 public function logout() {
        $this->Session->setFlash(__('You are now logged out.'));
        return $this->redirect($this->Auth->logout());
    }

Here's the deal.. Whenever I logout through the above logoutRedirect, and then log in, the user is not redirected to posts/index somehow.. and since I ve got DebugKit setup I tried to check whats going on an realised that within the cake Request Params, the controller is set to 'pages' and the action is 'display'.. This lead me to try and logout by manually entering the logout action URL in the address bar.. and guess what?! it works, and the user is redirected to the posts/index page.. So anyone knows how i can fix this issue im having? Or can point me towards a good source from which i can understand what and why is this happening exactly! thanks

1
do you supply any public page? - XuDing
Is the code you pasted from AppController? (public $components = ...) - cornelb
@cornelb Yes the code is from the AppController.. What Gaurav actually posted in his answer worked for me but it seems like a hack.. one which defeats the purpose of using the Auth component.. Am I mistaken ? thanks - LogixMaster
I don't undestand what you mean by logout through logout redirect - cornelb
I mean whenever the user is redirected to the 'login' action inside 'users' controller, through the defined config key logoutRedirect within the Auth, as shown above.. If the logout action is accessed by entering /users/logout in the url, rather then click on the logout link (which in turn gets the redirection url set iside the AppController components), it works and when the user logs in, he is redirected to the correct url - LogixMaster

1 Answers

-1
votes

Try this

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