@@ -76,20 +76,15 @@ First, enable form login under your firewall:
7676Now, when the security system initiates the authentication process, it will
7777redirect the user to the login form ``/login ``. Implementing this login form
7878visually is your job. First, create a new ``SecurityController `` inside a
79- bundle with an empty `` loginAction `` ::
79+ bundle::
8080
8181 // src/AppBundle/Controller/SecurityController.php
8282 namespace AppBundle\Controller;
8383
84- use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
8584 use Symfony\Bundle\FrameworkBundle\Controller\Controller;
8685
8786 class SecurityController extends Controller
8887 {
89- public function loginAction(Request $request)
90- {
91- // todo...
92- }
9388 }
9489
9590Next, create two routes: one for each of the paths your configured earlier
@@ -100,7 +95,9 @@ under your ``form_login`` configuration (``/login`` and ``/login_check``):
10095 .. code-block :: php-annotations
10196
10297 // src/AppBundle/Controller/SecurityController.php
98+
10399 // ...
100+ use Symfony\Component\HttpFoundation\Request;
104101 use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
105102
106103 class SecurityController extends Controller
@@ -110,14 +107,15 @@ under your ``form_login`` configuration (``/login`` and ``/login_check``):
110107 */
111108 public function loginAction(Request $request)
112109 {
113- // todo ...
114110 }
115111
116112 /**
117113 * @Route("/login_check", name="login_check")
118114 */
119115 public function loginCheckAction()
120116 {
117+ // this controller will not be executed,
118+ // as the route is handled by the Security system
121119 }
122120 }
123121
@@ -129,6 +127,8 @@ under your ``form_login`` configuration (``/login`` and ``/login_check``):
129127 defaults : { _controller: AppBundle:Security:login }
130128 login_check :
131129 path : /login_check
130+ # no controller is bound to this route
131+ # as it's handled by the Security system
132132
133133 .. code-block :: xml
134134
@@ -144,6 +144,8 @@ under your ``form_login`` configuration (``/login`` and ``/login_check``):
144144 </route >
145145
146146 <route id =" login_check" path =" /login_check" />
147+ <!-- no controller is bound to this route
148+ as it's handled by the Security system -->
147149 </routes >
148150
149151 .. code-block :: php
@@ -157,27 +159,27 @@ under your ``form_login`` configuration (``/login`` and ``/login_check``):
157159 '_controller' => 'AppBundle:Security:login',
158160 )));
159161 $collection->add('login_check', new Route('/login_check', array()));
162+ // no controller is bound to this route
163+ // as it's handled by the Security system
160164
161165 return $collection;
162166
163167 Great! Next, add the logic to ``loginAction `` that will display the login
164168form::
165169
166170 // src/AppBundle/Controller/SecurityController.php
167- // ...
168171
169- // ADD THIS use STATEMENT above your class
172+ // ...
170173 use Symfony\Component\Security\Core\SecurityContextInterface;
171174
175+ // ...
172176 public function loginAction(Request $request)
173177 {
174178 $session = $request->getSession();
175179
176180 // get the login error if there is one
177181 if ($request->attributes->has(SecurityContextInterface::AUTHENTICATION_ERROR)) {
178- $error = $request->attributes->get(
179- SecurityContextInterface::AUTHENTICATION_ERROR
180- );
182+ $error = $request->attributes->get(SecurityContextInterface::AUTHENTICATION_ERROR);
181183 } elseif (null !== $session && $session->has(SecurityContextInterface::AUTHENTICATION_ERROR)) {
182184 $error = $session->get(SecurityContextInterface::AUTHENTICATION_ERROR);
183185 $session->remove(SecurityContextInterface::AUTHENTICATION_ERROR);
0 commit comments