Adjust LoginForm to suit the "final" form builder implementation

refs #5525
This commit is contained in:
Johannes Meyer 2014-07-18 10:23:04 +02:00
parent f4ff2c90f2
commit 5da14d3fc5
2 changed files with 21 additions and 22 deletions

View File

@ -59,7 +59,8 @@ class AuthenticationController extends ActionController
} }
$chain = new AuthChain($config); $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')); $user = new User($this->view->form->getValue('username'));
$password = $this->view->form->getValue('password'); $password = $this->view->form->getValue('password');
$backendsTried = 0; $backendsTried = 0;
@ -107,7 +108,7 @@ class AuthenticationController extends ActionController
); );
} }
$this->view->form->getElement('password')->addError($this->translate('Incorrect username or password')); $this->view->form->getElement('password')->addError($this->translate('Incorrect username or password'));
} elseif (false === $this->view->form->isSubmitted()) { } elseif ($request->isGet()) {
$user = new User(''); $user = new User('');
foreach ($chain as $backend) { foreach ($chain as $backend) {
if ($backend instanceof AutoLoginBackend) { if ($backend instanceof AutoLoginBackend) {

View File

@ -16,51 +16,49 @@ class LoginForm extends Form
*/ */
public function init() public function init()
{ {
$this->setTokenDisabled();
$this->setName('form_login'); $this->setName('form_login');
$this->setSubmitLabel('Login');
} }
/** /**
* @see Form::createElements() * @see Form::createElements()
*/ */
public function createElements() public function createElements($formData)
{ {
return array( return array(
$this->createElement( $this->createElement(
'text', 'text',
'username', 'username',
array( array(
'required' => true,
'label' => t('Username'), 'label' => t('Username'),
'placeholder' => t('Please enter your username...'), 'placeholder' => t('Please enter your username...'),
'required' => true 'class' => false === isset($formData['username']) ? 'autofocus' : ''
) )
), ),
$this->createElement( $this->createElement(
'password', 'password',
'password', 'password',
array( array(
'required' => true,
'label' => t('Password'), 'label' => t('Password'),
'placeholder' => t('...and your password'), 'placeholder' => t('...and your password'),
'required' => true 'class' => isset($formData['username']) ? 'autofocus' : ''
) )
) )
); );
} }
/** /**
* @see Form::applyValues() * @see Form::addSubmitButton()
*/ */
public function applyValues(array $values) public function addSubmitButton()
{ {
parent::applyValues($values); $this->addElement(
'submit',
if (isset($values['username'])) { 'btn_submit',
$this->getElement('password')->setAttrib('class', 'autofocus'); array(
} else { 'label' => t('Login')
$this->getElement('username')->setAttrib('class', 'autofocus'); )
} );
return $this;
} }
} }