Skip to content

Commit 8488843

Browse files
committed
Tweaked the handling of error message in the login page
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).
1 parent 36d2dd2 commit 8488843

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

Changelog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
Changelog
22
=========
33

4+
### 2.0.0 (2014-XX-XX)
5+
6+
* [BC break] The ``FOSUserBundle:Security:login.html.twig`` template now receives an AuthenticationException in the ``error``
7+
variable rather than an error message.
8+
49
### 2.0.0-alpha1 (2014-09-26)
510

611
* Updated many translations

Controller/SecurityController.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,13 @@ public function loginAction(Request $request)
3030
$error = $session->get(SecurityContextInterface::AUTHENTICATION_ERROR);
3131
$session->remove(SecurityContextInterface::AUTHENTICATION_ERROR);
3232
} else {
33-
$error = '';
33+
$error = null;
3434
}
3535

36-
if ($error) {
37-
if ($error instanceof AuthenticationException) {
38-
$error = $error->getMessageKey();
39-
} else {
40-
// TODO: this is a potential security risk (see http://trac.symfony-project.org/ticket/9523)
41-
$error = $error->getMessage();
42-
}
36+
if (!$error instanceof AuthenticationException) {
37+
$error = null; // The value does not come from the security component.
4338
}
39+
4440
// last username entered by the user
4541
$lastUsername = (null === $session) ? '' : $session->get(SecurityContextInterface::LAST_USERNAME);
4642

Resources/views/Security/login.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
{% block fos_user_content %}
66
{% if error %}
7-
<div>{{ error|trans({}, 'security') }}</div>
7+
<div>{{ error.messageKey|trans(error.messageData, 'security') }}</div>
88
{% endif %}
99

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

0 commit comments

Comments
 (0)