@@ -25,7 +25,7 @@ First, enable form login under your firewall:
25
25
# app/config/security.yml
26
26
security :
27
27
# ...
28
-
28
+
29
29
firewalls :
30
30
default :
31
31
anonymous : ~
@@ -98,7 +98,7 @@ under your ``form_login`` configuration (``/login`` and ``/login_check``):
98
98
.. configuration-block ::
99
99
100
100
.. code-block :: php-annotations
101
-
101
+
102
102
// src/AppBundle/Controller/SecurityController.php
103
103
// ...
104
104
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
@@ -165,13 +165,14 @@ form::
165
165
166
166
// src/AppBundle/Controller/SecurityController.php
167
167
// ...
168
-
168
+
169
169
// ADD THIS use STATEMENT above your class
170
170
use Symfony\Component\Security\Core\SecurityContextInterface;
171
171
172
172
public function loginAction(Request $request)
173
173
{
174
174
$session = $request->getSession();
175
+ $error = null;
175
176
176
177
// get the login error if there is one
177
178
if ($request->attributes->has(SecurityContextInterface::AUTHENTICATION_ERROR)) {
@@ -181,8 +182,6 @@ form::
181
182
} elseif (null !== $session && $session->has(SecurityContextInterface::AUTHENTICATION_ERROR)) {
182
183
$error = $session->get(SecurityContextInterface::AUTHENTICATION_ERROR);
183
184
$session->remove(SecurityContextInterface::AUTHENTICATION_ERROR);
184
- } else {
185
- $error = '';
186
185
}
187
186
188
187
// last username entered by the user
@@ -218,7 +217,7 @@ Finally, create the template:
218
217
{# ... you will probably extends your base template, like base.html.twig #}
219
218
220
219
{% if error %}
221
- <div>{{ error.message }}</div>
220
+ <div>{{ error.messageKey|trans(error.messageData) }}</div>
222
221
{% endif %}
223
222
224
223
<form action="{{ path('login_check') }}" method="post">
0 commit comments