* @author Icinga Development Team */ // {{{ICINGA_LICENSE_HEADER}}} # namespace Icinga\Application\Controllers; use Icinga\Web\ActionController; use Icinga\Authentication\Credentials; use Icinga\Authentication\Manager as AuthManager; use Icinga\Form\Authentication\LoginForm; /** * Class AuthenticationController * @package Icinga\Application\Controllers */ class AuthenticationController extends ActionController { /** * Flag indicates authentication handling * @var bool */ protected $handlesAuthentication = true; /** * Flag indicates session modification * @var bool */ protected $modifiesSession = true; /** * Action to handle login */ public function loginAction() { $this->replaceLayout = true; $credentials = new Credentials(); $this->view->form = new LoginForm(); $this->view->form->setRequest($this->_request); try { $auth = AuthManager::getInstance(null, array( "writeSession" => true )); if ($auth->isAuthenticated()) { $this->redirectNow('index?_render=body'); } if ($this->view->form->isSubmittedAndValid()) { $credentials->setUsername($this->view->form->getValue('username')); $credentials->setPassword($this->view->form->getValue('password')); if (!$auth->authenticate($credentials)) { $this->view->form->getElement('password')->addError(t('Please provide a valid username and password')); } else { $this->redirectNow('index?_render=body'); } } } catch (\Icinga\Exception\ConfigurationError $configError) { $this->view->errorInfo = $configError->getMessage(); } } /** * Action handle logout */ public function logoutAction() { $auth = AuthManager::getInstance(null, array( "writeSession" => true )); $this->replaceLayout = true; $auth->removeAuthorization(); $this->redirect('login'); } } // @codingStandardsIgnoreEnd