Adjust LoginForm to suit the "final" form builder implementation
refs #5525
This commit is contained in:
parent
f4ff2c90f2
commit
5da14d3fc5
|
@ -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) {
|
||||||
|
|
|
@ -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(
|
||||||
'label' => t('Username'),
|
'required' => true,
|
||||||
'placeholder' => t('Please enter your username...'),
|
'label' => t('Username'),
|
||||||
'required' => true
|
'placeholder' => t('Please enter your username...'),
|
||||||
|
'class' => false === isset($formData['username']) ? 'autofocus' : ''
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
$this->createElement(
|
$this->createElement(
|
||||||
'password',
|
'password',
|
||||||
'password',
|
'password',
|
||||||
array(
|
array(
|
||||||
'label' => t('Password'),
|
'required' => true,
|
||||||
'placeholder' => t('...and your password'),
|
'label' => t('Password'),
|
||||||
'required' => true
|
'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);
|
$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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue