@@ -70,8 +70,7 @@ First, enable form login under your firewall:
7070
7171Now, when the security system initiates the authentication process, it will
7272redirect the user to the login form ``/login ``. Implementing this login form
73- visually is your job. First, create a new ``SecurityController `` inside a
74- bundle::
73+ is your job. First, create a new ``SecurityController `` inside a bundle::
7574
7675 // src/AppBundle/Controller/SecurityController.php
7776 namespace AppBundle\Controller;
@@ -139,8 +138,7 @@ configuration (``login``):
139138
140139 return $collection;
141140
142- Great! Next, add the logic to ``loginAction `` that will display the login
143- form::
141+ Great! Next, add the logic to ``loginAction `` that displays the login form::
144142
145143 // src/AppBundle/Controller/SecurityController.php
146144
@@ -154,14 +152,10 @@ form::
154152 // last username entered by the user
155153 $lastUsername = $authenticationUtils->getLastUsername();
156154
157- return $this->render(
158- 'security/login.html.twig',
159- array(
160- // last username entered by the user
161- 'last_username' => $lastUsername,
162- 'error' => $error,
163- )
164- );
155+ return $this->render('security/login.html.twig', array(
156+ 'last_username' => $lastUsername,
157+ 'error' => $error,
158+ ));
165159 }
166160
167161.. versionadded :: 2.6
@@ -239,13 +233,12 @@ Finally, create the template:
239233 It may contain more information - or even sensitive information - about
240234 the authentication failure, so use it wisely!
241235
242- The form can look like anything, but has a few requirements:
243-
244- * The form must POST to the ``login `` route, since that's what you configured
245- under the ``form_login `` key in ``security.yml ``.
236+ The form can look like anything, but it usually follows some conventions:
246237
247- * The username must have the name ``_username `` and the password must have
248- the name ``_password ``.
238+ * The ``<form> `` element sends a ``POST `` request to the ``login `` route, since
239+ that's what you configured under the ``form_login `` key in ``security.yml ``;
240+ * The username field has the name ``_username `` and the password field has the
241+ name ``_password ``.
249242
250243.. tip ::
251244
@@ -385,64 +378,6 @@ fixes the problem:
385378 array('path' => '^/', 'role' => 'ROLE_ADMIN'),
386379 ),
387380
388- Also, if your firewall does *not * allow for anonymous users (no ``anonymous ``
389- key), you'll need to create a special firewall that allows anonymous users
390- for the login page:
391-
392- .. configuration-block ::
393-
394- .. code-block :: yaml
395-
396- # app/config/security.yml
397-
398- # ...
399- firewalls :
400- # order matters! This must be before the ^/ firewall
401- login_firewall :
402- pattern : ^/login$
403- anonymous : ~
404- secured_area :
405- pattern : ^/
406- form_login : ~
407-
408- .. code-block :: xml
409-
410- <!-- app/config/security.xml -->
411- <?xml version =" 1.0" encoding =" UTF-8" ?>
412- <srv : container xmlns =" http://symfony.com/schema/dic/security"
413- xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
414- xmlns : srv =" http://symfony.com/schema/dic/services"
415- xsi : schemaLocation =" http://symfony.com/schema/dic/services
416- http://symfony.com/schema/dic/services/services-1.0.xsd" >
417-
418- <config >
419- <!-- ... -->
420- <firewall name =" login_firewall" pattern =" ^/login$" >
421- <anonymous />
422- </firewall >
423-
424- <firewall name =" secured_area" pattern =" ^/" >
425- <form-login />
426- </firewall >
427- </config >
428- </srv : container >
429-
430- .. code-block :: php
431-
432- // app/config/security.php
433-
434- // ...
435- 'firewalls' => array(
436- 'login_firewall' => array(
437- 'pattern' => '^/login$',
438- 'anonymous' => null,
439- ),
440- 'secured_area' => array(
441- 'pattern' => '^/',
442- 'form_login' => null,
443- ),
444- ),
445-
446381 3. Be Sure check_path Is Behind a Firewall
447382~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
448383
0 commit comments