Skip to content

Commit 9491960

Browse files
filled admin username is now prefilled again after invalid password
- autofocus on proper input was added
1 parent 240872c commit 9491960

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

src/Controller/Admin/LoginController.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,12 @@ public function loginAction(Request $request): Response
9090
};
9191
}
9292

93+
$lastUserName = $this->authenticationUtils->getLastUsername();
94+
$request->getSession()->remove(SecurityRequestAttributes::LAST_USERNAME);
95+
9396
return $this->render('@ShopsysFramework/Admin/Content/Login/loginForm.html.twig', [
9497
'form' => $form->createView(),
98+
'lastUsername' => $lastUserName,
9599
'error' => $error,
96100
]);
97101
}

src/Resources/views/Admin/Content/Login/loginForm.html.twig

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,33 @@
1919
<span class="box-login__error">
2020
{{ form_errors(form.username) }}
2121
</span>
22-
{{ form_widget(form.username, {attr: {placeholder: 'Username'|trans, class: 'box-login__input'}}) }}
22+
{% set
23+
usernameAttributes = {
24+
placeholder: 'Username'|trans,
25+
class: 'box-login__input',
26+
value: lastUsername
27+
}
28+
%}
29+
{% if not lastUsername %}
30+
{% set usernameAttributes = usernameAttributes|merge({'autofocus': 'autofocus'}) %}
31+
{% endif %}
32+
{{ form_widget(form.username, {attr: usernameAttributes}) }}
2333
</div>
2434

2535
<div class="box-login__row">
2636
<span class="box-login__error">
2737
{{ form_errors(form.password) }}
2838
</span>
29-
{{ form_widget(form.password, {attr: {placeholder: 'Password'|trans, class: 'box-login__input'}}) }}
39+
{% set
40+
passwordAttributes = {
41+
placeholder: 'Password'|trans,
42+
class: 'box-login__input',
43+
}
44+
%}
45+
{% if lastUsername %}
46+
{% set passwordAttributes = passwordAttributes|merge({'autofocus': 'autofocus'}) %}
47+
{% endif %}
48+
{{ form_widget(form.password, {attr: passwordAttributes}) }}
3049
</div>
3150

3251
<div class="box-login__row box-login__row--btn">

0 commit comments

Comments
 (0)