mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-03-18 23:49:55 +00:00
Adding a logout callback to authenticate objects.
Adding tests for the callback. Adding doc blocks for the new callback. Fixes #1758
This commit is contained in:
parent
be09c67fa6
commit
71933f5cf5
3 changed files with 34 additions and 1 deletions
|
@ -98,6 +98,18 @@ abstract class BaseAuthenticate {
|
||||||
*/
|
*/
|
||||||
abstract public function authenticate(CakeRequest $request, CakeResponse $response);
|
abstract public function authenticate(CakeRequest $request, CakeResponse $response);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allows you to hook into AuthComponent::logout(),
|
||||||
|
* and implement specialized logout behaviour.
|
||||||
|
*
|
||||||
|
* All attached authentication objects will have this method
|
||||||
|
* called when a user logs out.
|
||||||
|
*
|
||||||
|
* @param array $user The user about to be logged out.
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function logout($user) { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a user based on information in the request. Primarily used by stateless authentication
|
* Get a user based on information in the request. Primarily used by stateless authentication
|
||||||
* systems like basic and digest auth.
|
* systems like basic and digest auth.
|
||||||
|
@ -108,4 +120,4 @@ abstract class BaseAuthenticate {
|
||||||
public function getUser($request) {
|
public function getUser($request) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -516,6 +516,9 @@ class AuthComponent extends Component {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Logs a user out, and returns the login action to redirect to.
|
* Logs a user out, and returns the login action to redirect to.
|
||||||
|
* Triggers the logout() method of all the authenticate objects, so they can perform
|
||||||
|
* custom logout logic. AuthComponent will remove the session data, so
|
||||||
|
* there is no need to do that in an authentication object.
|
||||||
*
|
*
|
||||||
* @param mixed $url Optional URL to redirect the user to after logout
|
* @param mixed $url Optional URL to redirect the user to after logout
|
||||||
* @return string AuthComponent::$loginAction
|
* @return string AuthComponent::$loginAction
|
||||||
|
@ -524,6 +527,13 @@ class AuthComponent extends Component {
|
||||||
*/
|
*/
|
||||||
public function logout() {
|
public function logout() {
|
||||||
$this->__setDefaults();
|
$this->__setDefaults();
|
||||||
|
if (empty($this->_authenticateObjects)) {
|
||||||
|
$this->constructAuthenticate();
|
||||||
|
}
|
||||||
|
$user = $this->user();
|
||||||
|
foreach ($this->_authenticateObjects as $auth) {
|
||||||
|
$auth->logout($user);
|
||||||
|
}
|
||||||
$this->Session->delete(self::$sessionKey);
|
$this->Session->delete(self::$sessionKey);
|
||||||
$this->Session->delete('Auth.redirect');
|
$this->Session->delete('Auth.redirect');
|
||||||
return Router::normalize($this->logoutRedirect);
|
return Router::normalize($this->logoutRedirect);
|
||||||
|
|
|
@ -1061,6 +1061,17 @@ class AuthTest extends CakeTestCase {
|
||||||
$this->assertNull($this->Auth->Session->read('Auth.redirect'));
|
$this->assertNull($this->Auth->Session->read('Auth.redirect'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testLogoutTrigger() {
|
||||||
|
$this->getMock('BaseAuthenticate', array('authenticate', 'logout'), array(), 'LogoutTriggerMockAuthenticate', false);
|
||||||
|
|
||||||
|
$this->Auth->authenticate = array('LogoutTriggerMock');
|
||||||
|
$mock = $this->Auth->constructAuthenticate();
|
||||||
|
$mock[0]->expects($this->once())
|
||||||
|
->method('logout');
|
||||||
|
|
||||||
|
$this->Auth->logout();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test mapActions loading and delegating to authorize objects.
|
* test mapActions loading and delegating to authorize objects.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Reference in a new issue