Skip to content

Commit 3dd9998

Browse files
committed
feature #354 Use same URL for login form and check (WouterJ)
This PR was merged into the master branch. Discussion ---------- Use same URL for login form and check The Security Form login listener will only intercept the request when it's a POST request, otherwise the controller will be executed. Using the same URL makes things a bit easier, removes the need for the weird controller (which is visited, but should not be executed) and makes things similar to other forms. Related doc tickets: * symfony/symfony-docs#6126 * symfony/symfony-docs#6143 Commits ------- b7705cb Use same URL for login form and check
2 parents 08617a7 + b7705cb commit 3dd9998

File tree

4 files changed

+5
-19
lines changed

4 files changed

+5
-19
lines changed

app/Resources/views/blog/post_show.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
{{ render(controller('AppBundle:Blog:commentForm', { 'id': post.id })) }}
1919
{% else %}
2020
<p>
21-
<a class="btn btn-success" href="{{ path('security_login_form') }}">
21+
<a class="btn btn-success" href="{{ path('security_login') }}">
2222
<i class="fa fa-sign-in"></i> {{ 'action.sign_in'|trans }}
2323
</a>
2424
{{ 'post.to_publish_a_comment'|trans }}

app/Resources/views/security/login.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<div class="row">
1313
<div class="col-sm-5">
1414
<div class="well">
15-
<form action="{{ path('security_login_check') }}" method="post">
15+
<form action="{{ path('security_login') }}" method="post">
1616
<fieldset>
1717
<legend><i class="fa fa-lock"></i> {{ 'title.login'|trans }}</legend>
1818
<div class="form-group">

app/config/security.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ security:
2525
# Reference: http://symfony.com/doc/current/cookbook/security/form_login_setup.html
2626
form_login:
2727
# The route name that the login form submits to
28-
check_path: security_login_check
28+
check_path: security_login
2929
# The name of the route where the login form lives
3030
# When the user tries to access a protected page, they are redirected here
31-
login_path: security_login_form
31+
login_path: security_login
3232
# Secure the login form against CSRF
3333
# Reference: http://symfony.com/doc/current/cookbook/security/csrf_in_login_form.html
3434
csrf_token_generator: security.csrf.token_manager

src/AppBundle/Controller/SecurityController.php

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525
class SecurityController extends Controller
2626
{
2727
/**
28-
* @Route("/login", name="security_login_form")
29-
* @Method("GET")
28+
* @Route("/login", name="security_login")
3029
*/
3130
public function loginAction()
3231
{
@@ -40,19 +39,6 @@ public function loginAction()
4039
));
4140
}
4241

43-
/**
44-
* This is the route the login form submits to.
45-
*
46-
* But, this will never be executed. Symfony will intercept this first
47-
* and handle the login automatically. See form_login in app/config/security.yml
48-
*
49-
* @Route("/login_check", name="security_login_check")
50-
*/
51-
public function loginCheckAction()
52-
{
53-
throw new \Exception('This should never be reached!');
54-
}
55-
5642
/**
5743
* This is the route the user can use to logout.
5844
*

0 commit comments

Comments
 (0)