diff --git a/application/controllers/AuthenticationController.php b/application/controllers/AuthenticationController.php index 9ec057484..8812a21fc 100644 --- a/application/controllers/AuthenticationController.php +++ b/application/controllers/AuthenticationController.php @@ -59,7 +59,8 @@ class AuthenticationController extends ActionController } $chain = new AuthChain($config); - if ($this->view->form->isSubmittedAndValid($this->_request->getParams())) { + $request = $this->getRequest(); + if ($request->isPost() && $this->view->form->isValid($request->getPost())) { $user = new User($this->view->form->getValue('username')); $password = $this->view->form->getValue('password'); $backendsTried = 0; @@ -107,7 +108,7 @@ class AuthenticationController extends ActionController ); } $this->view->form->getElement('password')->addError($this->translate('Incorrect username or password')); - } elseif (false === $this->view->form->isSubmitted()) { + } elseif ($request->isGet()) { $user = new User(''); foreach ($chain as $backend) { if ($backend instanceof AutoLoginBackend) { diff --git a/application/forms/Authentication/LoginForm.php b/application/forms/Authentication/LoginForm.php index c6e5b23da..bbf65d22b 100644 --- a/application/forms/Authentication/LoginForm.php +++ b/application/forms/Authentication/LoginForm.php @@ -16,51 +16,49 @@ class LoginForm extends Form */ public function init() { - $this->setTokenDisabled(); $this->setName('form_login'); - $this->setSubmitLabel('Login'); } /** * @see Form::createElements() */ - public function createElements() + public function createElements($formData) { return array( $this->createElement( 'text', 'username', array( - 'label' => t('Username'), - 'placeholder' => t('Please enter your username...'), - 'required' => true + 'required' => true, + 'label' => t('Username'), + 'placeholder' => t('Please enter your username...'), + 'class' => false === isset($formData['username']) ? 'autofocus' : '' ) ), $this->createElement( 'password', 'password', array( - 'label' => t('Password'), - 'placeholder' => t('...and your password'), - 'required' => true + 'required' => true, + 'label' => t('Password'), + 'placeholder' => t('...and your password'), + 'class' => isset($formData['username']) ? 'autofocus' : '' ) ) ); } /** - * @see Form::applyValues() + * @see Form::addSubmitButton() */ - public function applyValues(array $values) + public function addSubmitButton() { - parent::applyValues($values); - - if (isset($values['username'])) { - $this->getElement('password')->setAttrib('class', 'autofocus'); - } else { - $this->getElement('username')->setAttrib('class', 'autofocus'); - } - - return $this; + $this->addElement( + 'submit', + 'btn_submit', + array( + 'label' => t('Login') + ) + ); } }