1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77:
<?php
namespace Nethgui\Module;
class Logout extends \Nethgui\Controller\AbstractController implements \Nethgui\Utility\SessionConsumerInterface
{
private $session;
protected function initializeAttributes(\Nethgui\Module\ModuleAttributesInterface $base)
{
$attributes = new SystemModuleAttributesProvider();
$attributes->initializeFromModule($this);
return $attributes;
}
public function initialize()
{
parent::initialize();
$this->declareParameter('action', '/^logout$/');
$this->declareParameter('nextPath', '/.*/');
}
public function process()
{
$request = $this->getRequest();
if ($request->isMutation() && $this->parameters['action'] === 'logout') {
$this->getLog()->notice(sprintf("%s: user %s logged out", __CLASS__, $request->getUser()->getCredential('username')));
$this->session->logout();
}
}
public function prepareView(\Nethgui\View\ViewInterface $view)
{
parent::prepareView($view);
$view['nextPath'] = '/' . implode('/', $this->getRequest()->getOriginalPath());
}
public function nextPath()
{
return $this->parameters['nextPath'] ? $this->parameters['nextPath'] : FALSE;
}
public function setSession(\Nethgui\Utility\SessionInterface $session)
{
$this->session = $session;
return $this;
}
}