@@ -70,8 +70,7 @@ First, enable form login under your firewall:
70
70
71
71
Now, when the security system initiates the authentication process, it will
72
72
redirect 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::
75
74
76
75
// src/AppBundle/Controller/SecurityController.php
77
76
namespace AppBundle\Controller;
@@ -139,8 +138,7 @@ configuration (``login``):
139
138
140
139
return $collection;
141
140
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::
144
142
145
143
// src/AppBundle/Controller/SecurityController.php
146
144
@@ -154,14 +152,10 @@ form::
154
152
// last username entered by the user
155
153
$lastUsername = $authenticationUtils->getLastUsername();
156
154
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
+ ));
165
159
}
166
160
167
161
.. versionadded :: 2.6
@@ -239,13 +233,12 @@ Finally, create the template:
239
233
It may contain more information - or even sensitive information - about
240
234
the authentication failure, so use it wisely!
241
235
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:
246
237
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 ``.
249
242
250
243
.. tip ::
251
244
@@ -385,64 +378,6 @@ fixes the problem:
385
378
array('path' => '^/', 'role' => 'ROLE_ADMIN'),
386
379
),
387
380
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
-
446
381
3. Be Sure check_path Is Behind a Firewall
447
382
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
448
383
0 commit comments