I'd like to customize the error message ('Bad credentials')if a there is a login error. I do it but doesn't work. This is the template login :
{% if error %}
<div>{{ error.message|trans }}</div>
{% endif %}<form action="{{ path('login_check') }}" method="post">
<label for="username">Username:</label>
<input type="text" id="username" name="_username" value="{{ last_username }}" />
<label for="password">Password:</label>
<input type="password" id="password" name="_password" />
<input type="hidden" name="_target_path" value="/account" />
<input type="submit" name="login" />
the file config.yml I have this :
framework:
#esi: ~
translator: { fallback: "%locale%" }
in parametre.yml I have this:
locale: en
I added the file in directory MyBundle/Resources/translations/messages.en.ymy:
security:
login:
username: "Username:"
password: "Password:"
submit: Login
forgot_username: "Forgot username"
forgot_password: "Forgot password"
registration: register
# Security
"Bad credentials": "Your user name or password are incorrect."
but always I have the Bad credentials error message
The problem is that error message has dot(.) at the end of the string.
You can correct this using the twig trim filter:
{{ error|trim('.')|trans({}, 'FOSUserBundle') }}
In my login form I have :
{# Error login form #}
{% if error %}
<div class="alert alert-danger">
<strong>{% trans %}login.error{% endtrans %}!</strong> {{ error.messageKey|trans({}, 'messages') }}
</div>
{% endif %}
Here the 'messages' is important as it refers the domain of your translation, or if you prefer the name of your translation file. In my case : messages.en.yml
With the fosuserbundle 1.3.5 you have to put this in your message.yml
"Invalid credentials." : Bad email/password combination
I hope this will help
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With