Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Merged
Merged
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletionscookbook/security/form_login_setup.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

you

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

nice catch - got it at sha:e245303

Expand All@@ -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
Expand All@@ -110,14 +107,15 @@ under your ``form_login`` configuration (``/login`` and ``/login_check``):
*/
public function loginAction(Request $request)
{
// todo ...
}

/**
* @Route("/login_check", name="login_check")
*/
public function loginCheckAction()
{
// this controller will not be executed,
// as the route is handled by the Security system
}
}

Expand All@@ -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

Expand All@@ -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
Expand All@@ -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
// ...

//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);
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp