diff --git a/application/controllers/AuthenticationController.php b/application/controllers/AuthenticationController.php index e6a038be1..e66bf3f95 100644 --- a/application/controllers/AuthenticationController.php +++ b/application/controllers/AuthenticationController.php @@ -71,6 +71,7 @@ class AuthenticationController extends ActionController if ($this->getRequest()->isPost() && $this->view->form->isValid($this->getRequest())) { + $credentials->setUsername($this->view->form->getValue('username')); $credentials->setPassword($this->view->form->getValue('password')); diff --git a/application/forms/Authentication/LoginForm.php b/application/forms/Authentication/LoginForm.php index 3c5f45782..242ae4a71 100644 --- a/application/forms/Authentication/LoginForm.php +++ b/application/forms/Authentication/LoginForm.php @@ -45,6 +45,7 @@ class LoginForm extends Form 'required' => true ) ); + $this->addElement( 'password', 'password', @@ -53,6 +54,7 @@ class LoginForm extends Form 'required' => true ) ); + $this->addElement( 'submit', 'submit', @@ -61,6 +63,7 @@ class LoginForm extends Form 'class' => 'pull-right' ) ); + $this->disableCsrfToken(); } } diff --git a/library/Icinga/Web/Form.php b/library/Icinga/Web/Form.php index 00d96219d..2fc54b997 100644 --- a/library/Icinga/Web/Form.php +++ b/library/Icinga/Web/Form.php @@ -61,6 +61,12 @@ abstract class Form extends \Zend_Form */ private $tokenTimeout = 300; + /** + * Flag to indicate that form is already build + * @var bool + */ + private $created = false; + /** * @see Zend_Form::init */ @@ -71,16 +77,15 @@ abstract class Form extends \Zend_Form } } + /** + * Render the form to html + * @param Zend_View_Interface $view + * @return string + */ public function render(Zend_View_Interface $view = null) { - if ($this->_isRendered === false) { - $this->create(); - - // Empty action if not safe - if (!$this->getAction() && $this->getRequest()) { - $this->setAction($this->getRequest()->getRequestUri()); - } - } + // Elements must be there to render the form + $this->buildForm(); return parent::render($view); } @@ -107,6 +112,23 @@ abstract class Form extends \Zend_Form return $this->request; } + /** + * Triggers form creation + */ + public function buildForm() + { + if ($this->created === false) { + $this->create(); + + // Empty action if not safe + if (!$this->getAction() && $this->getRequest()) { + $this->setAction($this->getRequest()->getRequestUri()); + } + + $this->created = true; + } + } + /** * Test if data from array or request is valid * @@ -119,6 +141,9 @@ abstract class Form extends \Zend_Form { $check = null; + // Elements must be there to validate + $this->buildForm(); + if ($data === null) { $check = $this->getRequest()->getParams(); } elseif ($data instanceof \Zend_Controller_Request_Abstract) {