Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
332 views
in Technique[技术] by (71.8m points)

php - CakePHP: on login, redirecting to last page viewed before logout

I've implemented Authentication and Authorization in Cake, and mostly it works as needed. However, if I hit log out from a page that requires particular credentials (say /admin) and log back in as another differently privileged user, I get redirected to /admin and an error message displayed.

Looking at the request headers in chrome, I notice that the Cookie CAKEPHP is still set even after log out.

public function login() {
    ...
        if ($this->Auth->login()) {
              $this->set('login_failed', false);
        return $this->redirect($this->Auth->redirect());
    } else {
    ...
    }
}


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

Any ideas about how I can troubleshoot this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

assign this to your AppController

public $components = array(               
        'Auth'=> array(                
            'logoutRedirect' => array('controller' => 'users', 'action'=>'login'),
            'loginRedirect' => array('controller' => 'users', 'action' => 'login')
          )
)

your logout function also is incorrect. You should do this:

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

loginRedirect

logoutRedirect


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...