From f804af90524342219f55494c88822be8223d9709 Mon Sep 17 00:00:00 2001 From: WouterJ Date: Sat, 21 Feb 2015 10:29:31 +0100 Subject: [PATCH] Reread Form Login article --- cookbook/security/form_login_setup.rst | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) 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); pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy