0
votes

Hi I'm using cakephp auth component for login system, I would like,every time when user login to redirect him to users page,but when session is timeout and user login again he is redirected to previous page that he was on,and not back to users page.I hope you understand me.He is my code.

app controller :

function beforeFilter() {
    $this->Auth->loginAction = array('admin' => false, 'controller' => 'users', 'action' => 'login');

    $this->Auth->loginRedirect = array('admin' => false, 'controller' => 'books', 'action' => 'index');

    $this->Auth->allow('display');
}

users controller :

function login() {
            }

    function admin_logout() {
        $this->Session->destroy(); 
        $this->redirect($this->Auth->logout());

    }
2
Why would you want to redirect the user out of the page he was on? If he was doing something on your site and his session times out and is refreshed it's a better user experience if he picks up where he left off - 8vius
I know,it doesn't make sense,but I want to do that. - user147

2 Answers

2
votes

in beforeFilter in users controller, add $this->Auth->autoRedirect = false; and

function login() {
    if($this->Auth->user())$this->redirect(array('controller' => 'books', 'action' => 'index'));
}
0
votes

This is kind of a tricky one, because I think the Session component will not let you do what it is you want unless you modify it, what you can do is open config/core.php in your app and modify your Security.level and Session.timeout variables to be longer, the security level works as a multiplier for the timeout variable if it's high the multiplier is 10, 100 if it's medium and 300 if it's low