Skip to content

Commit d9515db

Browse files
committed
fixed the example of a login form
1 parent accb062 commit d9515db

File tree

1 file changed

+35
-13
lines changed

1 file changed

+35
-13
lines changed

guides/security/authentication.rst

+35-13
Original file line numberDiff line numberDiff line change
@@ -280,35 +280,57 @@ yourself::
280280
}
281281
}
282282

283-
And the corresponding template::
283+
And the corresponding template:
284284

285-
<?php if ($error): ?>
286-
<div><?php echo $error ?></div>
287-
<?php endif; ?>
285+
.. configuration-block::
286+
287+
.. code-block:: html+php
288+
289+
<?php if ($error): ?>
290+
<div><?php echo $error ?></div>
291+
<?php endif; ?>
292+
293+
<form action="<?php echo $view['router']->generate('_security_check') ?>" method="post">
294+
<label for="username">Username:</label>
295+
296+
<input type="text" id="username" name="_username" value="<?php echo $last_username ?>" />
297+
<label for="password">Password:</label>
298+
<input type="password" id="password" name="_password" />
288299

289-
<form action="/_login_check" method="post">
290-
<label for="username">Username:</label>
300+
<input type="submit" name="login" />
301+
</form>
291302

292-
<input type="text" id="username" name="_username" value="<?php echo $last_username ?>" />
293-
<label for="password">Password:</label>
294-
<input type="password" id="password" name="_password" />
303+
.. code-block:: jinja
295304
296-
<input type="submit" name="login" />
297-
</form>
305+
{% if error %}
306+
<div>{{ error }}</div>
307+
{% endif %}
308+
309+
<form action="{% route "_security_check" %}" method="post">
310+
<label for="username">Username:</label>
311+
312+
<input type="text" id="username" name="_username" value="{{ last_username }}" />
313+
<label for="password">Password:</label>
314+
<input type="password" id="password" name="_password" />
315+
316+
<input type="submit" name="login" />
317+
</form>
298318
299319
The template must have a ``_username`` and ``_password`` fields, and the form
300320
submission URL must be the value of the ``check_path`` setting
301321
(``/login_check`` by default).
302322

303-
Finally, you will need to route the controller to the ``/login`` URL
304-
(``login_path`` value):
323+
Finally, add routes for the ``/login`` (``login_path`` value) and
324+
``/_login_check`` (``login_check`` value) URLs:
305325

306326
.. code-block:: xml
307327
308328
<route id="_security_login" pattern="/login">
309329
<default key="_controller">SecurityBundle:Security:login</default>
310330
</route>
311331
332+
<route id="_security_check" pattern="/_login_check" />
333+
312334
After an authentication failure, the user is redirected to the login page. You
313335
can use forward instead by setting the ``failure_forward`` to ``true``. You
314336
can also redirect or forward to another page if you set the ``failure_path``

0 commit comments

Comments
 (0)