Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit269e364

Browse files
committed
document the new AuthenticationUtils
1 parent640b29e commit269e364

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

‎cookbook/security/form_login_setup.rst

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ First, enable form login under your firewall:
2525
# app/config/security.yml
2626
security:
2727
# ...
28-
28+
2929
firewalls:
3030
default:
3131
anonymous:~
@@ -98,7 +98,7 @@ under your ``form_login`` configuration (``/login`` and ``/login_check``):
9898
..configuration-block::
9999

100100
..code-block::php-annotations
101-
101+
102102
// src/AppBundle/Controller/SecurityController.php
103103
// ...
104104
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
@@ -165,39 +165,35 @@ form::
165165

166166
// src/AppBundle/Controller/SecurityController.php
167167
// ...
168-
168+
169169
// ADD THIS use STATEMENT above your class
170170
use Symfony\Component\Security\Core\Security;
171171

172172
public function loginAction(Request $request)
173173
{
174-
$session = $request->getSession();
174+
$authenticationUtils = $this->get('security.authentication_utils');
175175

176176
// 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 = '';
186-
}
177+
$error = $authenticationUtils->getLastAuthenticationError();
187178

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

191182
return $this->render(
192183
'security/login.html.twig',
193184
array(
194185
// last username entered by the user
195186
'last_username' => $lastUsername,
196-
'error' => $error,
187+
'error' => $error ?: '',
197188
)
198189
);
199190
}
200191

192+
..versionadded::2.6
193+
The ``security.authencation_utils`` service and the
194+
:class:`Symfony\\Component\\Security\\Http\\Authentication\\AuthenticationUtils`
195+
class were introduced in Symfony 2.6.
196+
201197
Don't let this controller confuse you. As you'll see in a moment, when the
202198
user submits the form, the security system automatically handles the form
203199
submission for you. If the user had submitted an invalid username or password,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp