diff --git a/cookbook/security/form_login_setup.rst b/cookbook/security/form_login_setup.rst index 011ab6f6894..cfed1d88679 100644 --- a/cookbook/security/form_login_setup.rst +++ b/cookbook/security/form_login_setup.rst @@ -76,20 +76,15 @@ First, enable form login under your firewall: Now, when the security system initiates the authentication process, it will redirect the user to the login form ``/login``. Implementing this login form visually is your job. First, create a new ``SecurityController`` inside a -bundle with an empty ``loginAction``:: +bundle:: // src/AppBundle/Controller/SecurityController.php namespace AppBundle\Controller; - use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Symfony\Bundle\FrameworkBundle\Controller\Controller; class SecurityController extends Controller { - public function loginAction(Request $request) - { - // todo... - } } Next, 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``): .. code-block:: php-annotations // src/AppBundle/Controller/SecurityController.php + // ... + use Symfony\Component\HttpFoundation\Request; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; class SecurityController extends Controller @@ -110,7 +107,6 @@ under your ``form_login`` configuration (``/login`` and ``/login_check``): */ public function loginAction(Request $request) { - // todo ... } /** @@ -118,6 +114,8 @@ under your ``form_login`` configuration (``/login`` and ``/login_check``): */ public function loginCheckAction() { + // this controller will not be executed, + // as the route is handled by the Security system } } @@ -129,6 +127,8 @@ under your ``form_login`` configuration (``/login`` and ``/login_check``): defaults: { _controller: AppBundle:Security:login } login_check: path: /login_check + # no controller is bound to this route + # as it's handled by the Security system .. code-block:: xml @@ -144,6 +144,8 @@ under your ``form_login`` configuration (``/login`` and ``/login_check``): + .. code-block:: php @@ -157,6 +159,8 @@ under your ``form_login`` configuration (``/login`` and ``/login_check``): '_controller' => 'AppBundle:Security:login', ))); $collection->add('login_check', new Route('/login_check', array())); + // no controller is bound to this route + // as it's handled by the Security system return $collection; @@ -164,20 +168,18 @@ Great! Next, add the logic to ``loginAction`` that will display the login form:: // src/AppBundle/Controller/SecurityController.php - // ... - // ADD THIS use STATEMENT above your class + // ... use Symfony\Component\Security\Core\SecurityContextInterface; + // ... public function loginAction(Request $request) { $session = $request->getSession(); // get the login error if there is one if ($request->attributes->has(SecurityContextInterface::AUTHENTICATION_ERROR)) { - $error = $request->attributes->get( - SecurityContextInterface::AUTHENTICATION_ERROR - ); + $error = $request->attributes->get(SecurityContextInterface::AUTHENTICATION_ERROR); } elseif (null !== $session && $session->has(SecurityContextInterface::AUTHENTICATION_ERROR)) { $error = $session->get(SecurityContextInterface::AUTHENTICATION_ERROR); $session->remove(SecurityContextInterface::AUTHENTICATION_ERROR);