Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork5.2k
A very quick reread of the Form Login article#5036
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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:: | ||
// src/AppBundle/Controller/SecurityController.php | ||
namespace AppBundle\Controller; | ||
use Symfony\Bundle\FrameworkBundle\Controller\Controller; | ||
class SecurityController extends Controller | ||
{ | ||
} | ||
Next, create two routes: one for each of the paths your configured earlier | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. you There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. nice catch - got it at sha:e245303 | ||
@@ -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,14 +107,15 @@ under your ``form_login`` configuration (``/login`` and ``/login_check``): | ||
*/ | ||
public function loginAction(Request $request) | ||
{ | ||
} | ||
/** | ||
* @Route("/login_check", name="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``): | ||
</route> | ||
<route id="login_check" path="/login_check" /> | ||
<!-- no controller is bound to this route | ||
as it's handled by the Security system --> | ||
</routes> | ||
.. code-block:: php | ||
@@ -157,27 +159,27 @@ 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; | ||
Great! Next, add the logic to ``loginAction`` that will display the login | ||
form:: | ||
// src/AppBundle/Controller/SecurityController.php | ||
//... | ||
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); | ||
} elseif (null !== $session && $session->has(SecurityContextInterface::AUTHENTICATION_ERROR)) { | ||
$error = $session->get(SecurityContextInterface::AUTHENTICATION_ERROR); | ||
$session->remove(SecurityContextInterface::AUTHENTICATION_ERROR); | ||