Ibexa DXP Discussions

Community discussion forum for developers working with Ibexa DXP

Return to the original page after a connection failure

Hy all,

On my site I have restricted access articles.

Logged-in users can read the entire article.
Anonymous users can only read the beginning and are invited to create an account or login.


{% if user.login == "anonymous" %}
  {# only intro #} 
  {% include 'EdbPressePro3Bundle:security:__login_form.html.twig' with {'target_path': url( location ), 'failure_path': url( location )} %}
{% else %}
  {# full article#}
{% endif %}


{% if error|default(false) %}
    <div class="alert alert-danger">{{ error.message|trans }}</div>
{% endif %}
<form action="{{ path( 'login_check' ) }}" method="post" role="form">
            <label for="username">{{ 'Username:'|trans }}</label>
            <input type="text" id="username" name="_username" required="required" />

            <label for="password">{{ 'Password:'|trans }}</label>
            <input type="password" id="password" name="_password" required="required" />

            <input type="hidden" name="_csrf_token" value="{{ csrf_token("authenticate") }}" />

            {% if target_path is defined %}
                <input type="hidden" name="_target_path" value="{{ target_path }}" />
            {% endif %}

            {% if failure_path is defined %}
                <input type="hidden" name="_failure_path" value="{{ failure_path }}" />
            {% endif %}

            <button type="submit">{{ 'Login'|trans }}</button>

If the user connects successfully there is no problem. It remains of course on the article and now has full access.

But if he’s wrong I don’t have the error message to display. error doesn’t exist.

If I don’t pass the _failure_path variable, the user arrives on /login and there is the error message :“Bad credentials”

But I’d like him to stay on the article.
In addition; Even if he finally succeeds in connecting he is not returning to his article.