@@ -26,8 +26,8 @@ First, enable form login under your firewall:
2626 main :
2727 anonymous : ~
2828 form_login :
29- login_path : / login
30- check_path : /login_check
29+ login_path : login
30+ check_path : login
3131
3232 .. code-block :: xml
3333
@@ -42,7 +42,7 @@ First, enable form login under your firewall:
4242 <config >
4343 <firewall name =" main" >
4444 <anonymous />
45- <form-login login-path =" /login" check-path =" /login_check " />
45+ <form-login login-path =" /login" check-path =" /login " />
4646 </firewall >
4747 </config >
4848 </srv : container >
@@ -55,8 +55,8 @@ First, enable form login under your firewall:
5555 'main' => array(
5656 'anonymous' => null,
5757 'form_login' => array(
58- 'login_path' => '/ login',
59- 'check_path' => '/login_check ',
58+ 'login_path' => 'login',
59+ 'check_path' => 'login ',
6060 ),
6161 ),
6262 ),
@@ -82,8 +82,8 @@ bundle::
8282 {
8383 }
8484
85- Next, create two routes: one for each of the paths you configured earlier
86- under your ``form_login `` configuration (``/login `` and `` /login_check `` ):
85+ Next, create a route for the path you configured earlier
86+ under your ``form_login `` configuration (``/login ``):
8787
8888.. configuration-block ::
8989
@@ -98,34 +98,20 @@ under your ``form_login`` configuration (``/login`` and ``/login_check``):
9898 class SecurityController extends Controller
9999 {
100100 /**
101- * @Route("/login", name="login_route ")
101+ * @Route("/login", name="login ")
102102 */
103103 public function loginAction(Request $request)
104104 {
105105 }
106-
107- /**
108- * @Route("/login_check", name="login_check")
109- */
110- public function loginCheckAction()
111- {
112- // this controller will not be executed,
113- // as the route is handled by the Security system
114- }
115106 }
116107
117108 .. code-block :: yaml
118109
119110 # app/config/routing.yml
120- login_route :
111+ login :
121112 path : /login
122113 defaults : { _controller: AppBundle:Security:login }
123114
124- login_check :
125- path : /login_check
126- # no controller is bound to this route
127- # as it's handled by the Security system
128-
129115 .. code-block :: xml
130116
131117 <!-- app/config/routing.xml -->
@@ -135,13 +121,9 @@ under your ``form_login`` configuration (``/login`` and ``/login_check``):
135121 xsi : schemaLocation =" http://symfony.com/schema/routing
136122 http://symfony.com/schema/routing/routing-1.0.xsd" >
137123
138- <route id =" login_route " path =" /login" >
124+ <route id =" login " path =" /login" >
139125 <default key =" _controller" >AppBundle:Security:login</default >
140126 </route >
141-
142- <route id =" login_check" path =" /login_check" />
143- <!-- no controller is bound to this route
144- as it's handled by the Security system -->
145127 </routes >
146128
147129 .. code-block :: php
@@ -151,14 +133,10 @@ under your ``form_login`` configuration (``/login`` and ``/login_check``):
151133 use Symfony\Component\Routing\Route;
152134
153135 $collection = new RouteCollection();
154- $collection->add('login_route ', new Route('/login', array(
136+ $collection->add('login ', new Route('/login', array(
155137 '_controller' => 'AppBundle:Security:login',
156138 )));
157139
158- $collection->add('login_check', new Route('/login_check'));
159- // no controller is bound to this route
160- // as it's handled by the Security system
161-
162140 return $collection;
163141
164142 Great! Next, add the logic to ``loginAction `` that will display the login
@@ -220,7 +198,7 @@ Finally, create the template:
220198 <div>{{ error.messageKey|trans(error.messageData, 'security') }}</div>
221199 {% endif %}
222200
223- <form action="{{ path('login_check ') }}" method="post">
201+ <form action="{{ path('login ') }}" method="post">
224202 <label for="username">Username:</label>
225203 <input type="text" id="username" name="_username" value="{{ last_username }}" />
226204
@@ -243,7 +221,7 @@ Finally, create the template:
243221 <div><?php echo $error->getMessage() ?></div>
244222 <?php endif ?>
245223
246- <form action="<?php echo $view['router']->generate('login_check ') ?>" method="post">
224+ <form action="<?php echo $view['router']->generate('login ') ?>" method="post">
247225 <label for="username">Username:</label>
248226 <input type="text" id="username" name="_username" value="<?php echo $last_username ?>" />
249227
@@ -269,7 +247,7 @@ Finally, create the template:
269247
270248The form can look like anything, but has a few requirements:
271249
272- * The form must POST to ``/login_check ``, since that's what you configured
250+ * The form must POST to ``/login ``, since that's what you configured
273251 under the ``form_login `` key in ``security.yml ``.
274252
275253* The username must have the name ``_username `` and the password must have
@@ -297,7 +275,7 @@ To review the whole process:
297275 user to the login form (``/login ``);
298276#. The ``/login `` page renders login form via the route and controller created
299277 in this example;
300- #. The user submits the login form to ``/login_check ``;
278+ #. The user submits the login form to ``/login ``;
301279#. The security system intercepts the request, checks the user's submitted
302280 credentials, authenticates the user if they are correct, and sends the
303281 user back to the login form if they are not.
@@ -324,12 +302,11 @@ When setting up your login form, watch out for a few common pitfalls.
3243021. Create the Correct Routes
325303~~~~~~~~~~~~~~~~~~~~~~~~~~~~
326304
327- First, be sure that you've defined the ``/login `` and ``/login_check ``
328- routes correctly and that they correspond to the ``login_path `` and
329- ``check_path `` config values. A misconfiguration here can mean that you're
330- redirected to a 404 page instead of the login page, or that submitting
331- the login form does nothing (you just see the login form over and over
332- again).
305+ First, be sure that you've defined the ``/login `` route correctly and that
306+ it corresponds to the ``login_path `` and``check_path`` config values.
307+ A misconfiguration here can mean that you're redirected to a 404 page instead
308+ of the login page, or that submitting the login form does nothing (you just see
309+ the login form over and over again).
333310
3343112. Be Sure the Login Page Isn't Secure (Redirect Loop!)
335312~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -472,14 +449,14 @@ for the login page:
472449 ),
473450 ),
474451
475- 3. Be Sure /login_check Is Behind a Firewall
476- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
452+ 3. Be Sure check_path Is Behind a Firewall
453+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
477454
478- Next, make sure that your ``check_path `` URL (e.g. ``/login_check ``) is behind
455+ Next, make sure that your ``check_path `` URL (e.g. ``/login ``) is behind
479456the firewall you're using for your form login (in this example, the single
480- firewall matches *all * URLs, including ``/login_check ``). If ``/login_check ``
457+ firewall matches *all * URLs, including ``/login ``). If ``/login ``
481458doesn't match any firewall, you'll receive a ``Unable to find the controller
482- for path "/login_check " `` exception.
459+ for path "/login " `` exception.
483460
4844614. Multiple Firewalls Don't Share the Same Security Context
485462~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0 commit comments