Skip to content

Commit 3643ec2

Browse files
committed
feature #4723 [Cookbook][Security] document the new AuthenticationUtils (xabbuh)
This PR was merged into the 2.6 branch. Discussion ---------- [Cookbook][Security] document the new AuthenticationUtils | Q | A | ------------- | --- | Doc fix? | no | New docs? | yes (symfony/symfony#11324) | Applies to | 2.6+ | Fixed tickets | #3996 Commits ------- dd7c1dd document the new AuthenticationUtils
2 parents 4b0ebea + dd7c1dd commit 3643ec2

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

cookbook/security/form_login_setup.rst

+8-15
Original file line numberDiff line numberDiff line change
@@ -166,27 +166,15 @@ form::
166166
// src/AppBundle/Controller/SecurityController.php
167167
// ...
168168

169-
// ADD THIS use STATEMENT above your class
170-
use Symfony\Component\Security\Core\Security;
171-
172169
public function loginAction(Request $request)
173170
{
174-
$session = $request->getSession();
171+
$authenticationUtils = $this->get('security.authentication_utils');
175172

176173
// get the login error if there is one
177-
if ($request->attributes->has(Security::AUTHENTICATION_ERROR)) {
178-
$error = $request->attributes->get(
179-
Security::AUTHENTICATION_ERROR
180-
);
181-
} elseif (null !== $session && $session->has(Security::AUTHENTICATION_ERROR)) {
182-
$error = $session->get(Security::AUTHENTICATION_ERROR);
183-
$session->remove(Security::AUTHENTICATION_ERROR);
184-
} else {
185-
$error = null;
186-
}
174+
$error = $authenticationUtils->getLastAuthenticationError();
187175

188176
// last username entered by the user
189-
$lastUsername = (null === $session) ? '' : $session->get(Security::LAST_USERNAME);
177+
$lastUsername = $authenticationUtils->getLastUsername();
190178

191179
return $this->render(
192180
'security/login.html.twig',
@@ -198,6 +186,11 @@ form::
198186
);
199187
}
200188

189+
.. versionadded:: 2.6
190+
The ``security.authentication_utils`` service and the
191+
:class:`Symfony\\Component\\Security\\Http\\Authentication\\AuthenticationUtils`
192+
class were introduced in Symfony 2.6.
193+
201194
Don't let this controller confuse you. As you'll see in a moment, when the
202195
user submits the form, the security system automatically handles the form
203196
submission for you. If the user had submitted an invalid username or password,

0 commit comments

Comments
 (0)