@@ -76,20 +76,15 @@ First, enable form login under your firewall:
76
76
Now, when the security system initiates the authentication process, it will
77
77
redirect the user to the login form ``/login ``. Implementing this login form
78
78
visually is your job. First, create a new ``SecurityController `` inside a
79
- bundle with an empty `` loginAction `` ::
79
+ bundle::
80
80
81
81
// src/AppBundle/Controller/SecurityController.php
82
82
namespace AppBundle\Controller;
83
83
84
- use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
85
84
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
86
85
87
86
class SecurityController extends Controller
88
87
{
89
- public function loginAction(Request $request)
90
- {
91
- // todo...
92
- }
93
88
}
94
89
95
90
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``):
100
95
.. code-block :: php-annotations
101
96
102
97
// src/AppBundle/Controller/SecurityController.php
98
+
103
99
// ...
100
+ use Symfony\Component\HttpFoundation\Request;
104
101
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
105
102
106
103
class SecurityController extends Controller
@@ -110,14 +107,15 @@ under your ``form_login`` configuration (``/login`` and ``/login_check``):
110
107
*/
111
108
public function loginAction(Request $request)
112
109
{
113
- // todo ...
114
110
}
115
111
116
112
/**
117
113
* @Route("/login_check", name="login_check")
118
114
*/
119
115
public function loginCheckAction()
120
116
{
117
+ // this controller will not be executed,
118
+ // as the route is handled by the Security system
121
119
}
122
120
}
123
121
@@ -129,6 +127,8 @@ under your ``form_login`` configuration (``/login`` and ``/login_check``):
129
127
defaults : { _controller: AppBundle:Security:login }
130
128
login_check :
131
129
path : /login_check
130
+ # no controller is bound to this route
131
+ # as it's handled by the Security system
132
132
133
133
.. code-block :: xml
134
134
@@ -144,6 +144,8 @@ under your ``form_login`` configuration (``/login`` and ``/login_check``):
144
144
</route >
145
145
146
146
<route id =" login_check" path =" /login_check" />
147
+ <!-- no controller is bound to this route
148
+ as it's handled by the Security system -->
147
149
</routes >
148
150
149
151
.. code-block :: php
@@ -157,27 +159,27 @@ under your ``form_login`` configuration (``/login`` and ``/login_check``):
157
159
'_controller' => 'AppBundle:Security:login',
158
160
)));
159
161
$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
160
164
161
165
return $collection;
162
166
163
167
Great! Next, add the logic to ``loginAction `` that will display the login
164
168
form::
165
169
166
170
// src/AppBundle/Controller/SecurityController.php
167
- // ...
168
171
169
- // ADD THIS use STATEMENT above your class
172
+ // ...
170
173
use Symfony\Component\Security\Core\SecurityContextInterface;
171
174
175
+ // ...
172
176
public function loginAction(Request $request)
173
177
{
174
178
$session = $request->getSession();
175
179
176
180
// get the login error if there is one
177
181
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);
181
183
} elseif (null !== $session && $session->has(SecurityContextInterface::AUTHENTICATION_ERROR)) {
182
184
$error = $session->get(SecurityContextInterface::AUTHENTICATION_ERROR);
183
185
$session->remove(SecurityContextInterface::AUTHENTICATION_ERROR);
0 commit comments