开发者

cakephp login redirect problem?

开发者 https://www.devze.com 2023-04-02 01:19 出处:网络
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 previo

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, 'contro开发者_C百科ller' => '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());

    }


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

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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消