Skip to content

Commit

Permalink
Added logout Event and trigger
Browse files Browse the repository at this point in the history
Chainable Adapter is registered to the events it offers
USer Controller calls logout on the adapters
  • Loading branch information
pdobrigkeit committed Oct 12, 2012
1 parent af1b534 commit 92727fb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
11 changes: 11 additions & 0 deletions src/ZfcUser/Authentication/Adapter/AdapterChain.php
Expand Up @@ -79,6 +79,17 @@ public function resetAdapters()
$this;
}

/**
* logoutAdapters
*
* @return AdapterChain
*/
public function logoutAdapters()
{
//Adapters might need to perform additional cleanup after logout
$this->getEventManager()->trigger('logout', $this->getEvent());
}

/**
* Get the auth event
*
Expand Down
13 changes: 10 additions & 3 deletions src/ZfcUser/Authentication/Adapter/AdapterChainServiceFactory.php
Expand Up @@ -13,12 +13,19 @@ public function createService(ServiceLocatorInterface $serviceLocator)

$options = $serviceLocator->get('zfcuser_module_options');

//iterate and attach multiple adapters
//iterate and attach multiple adapters and events if offered
foreach($options->getAuthAdapters() as $priority => $adapterName) {
$adapter = $serviceLocator->get($adapterName);
$chain->getEventManager()->attach('authenticate', array($adapter, 'authenticate'), $priority);

if(is_callable(array($adapter, 'authenticate'))) {
$chain->getEventManager()->attach('authenticate', array($adapter, 'authenticate'), $priority);
}

if(is_callable(array($adapter, 'logout'))) {
$chain->getEventManager()->attach('logout', array($adapter, 'logout'), $priority);
}
}

return $chain;
}
}
}
1 change: 1 addition & 0 deletions src/ZfcUser/Controller/UserController.php
Expand Up @@ -98,6 +98,7 @@ public function loginAction()
public function logoutAction()
{
$this->zfcUserAuthentication()->getAuthAdapter()->resetAdapters();
$this->zfcUserAuthentication()->getAuthAdapter()->logoutAdapters();
$this->zfcUserAuthentication()->getAuthService()->clearIdentity();

$redirect = ($this->getRequest()->getPost()->get('redirect')) ? $this->getRequest()->getPost()->get('redirect') : false;
Expand Down

0 comments on commit 92727fb

Please sign in to comment.