Skip to content

Commit

Permalink
Tweaked the handling of error message in the login page
Browse files Browse the repository at this point in the history
The template now receives the AuthenticationException instead of only
its message key, allowing to support translation parameters.
Other exceptions are not rendered anymore (it should not happen anyway
as the Security system always use an AuthenticationException to fill the
attribute).
  • Loading branch information
stof committed Sep 26, 2014
1 parent 36d2dd2 commit 8488843
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
5 changes: 5 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Changelog
=========

### 2.0.0 (2014-XX-XX)

* [BC break] The ``FOSUserBundle:Security:login.html.twig`` template now receives an AuthenticationException in the ``error``
variable rather than an error message.

### 2.0.0-alpha1 (2014-09-26)

* Updated many translations
Expand Down
12 changes: 4 additions & 8 deletions Controller/SecurityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,13 @@ public function loginAction(Request $request)
$error = $session->get(SecurityContextInterface::AUTHENTICATION_ERROR);
$session->remove(SecurityContextInterface::AUTHENTICATION_ERROR);
} else {
$error = '';
$error = null;
}

if ($error) {
if ($error instanceof AuthenticationException) {
$error = $error->getMessageKey();
} else {
// TODO: this is a potential security risk (see http://trac.symfony-project.org/ticket/9523)
$error = $error->getMessage();
}
if (!$error instanceof AuthenticationException) {
$error = null; // The value does not come from the security component.
}

// last username entered by the user
$lastUsername = (null === $session) ? '' : $session->get(SecurityContextInterface::LAST_USERNAME);

Expand Down
2 changes: 1 addition & 1 deletion Resources/views/Security/login.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

{% block fos_user_content %}
{% if error %}
<div>{{ error|trans({}, 'security') }}</div>
<div>{{ error.messageKey|trans(error.messageData, 'security') }}</div>
{% endif %}

<form action="{{ path("fos_user_security_check") }}" method="post">
Expand Down

0 comments on commit 8488843

Please sign in to comment.