0

I have create a identification form but an error message "Bad login" appears even without submit form.

I use an account with the app/config/security.yml for check the form.

My controller :

public function loginAction() {

    $request = $this->getRequest();
    $session = $request->getSession();
    $error = null;

    if ($request->attributes->has(SecurityContext::AUTHENTICATION_ERROR)) {
        $error = "Oop's ! Bad login";
    } else {
        $error = "Oop's ! Bad login";
        $session->remove(SecurityContext::AUTHENTICATION_ERROR);
    }

    return $this->render('CmsCmsBundle:Main:Log/login.html.twig', array(
        'last_username' => $session->get(SecurityContext::LAST_USERNAME),
        'error'         => $error,
    ));
}

My view :

{% if error %}
<div class="flash flash-error">
{{ error }}
</div> {% endif %}
<form action="{{ path('cms_cms_logcheck') }}" method="post">
            <div class="form-align">
                <label for="username">Login :</label>
                <input type="text" id="username" name="_username" value="{{ last_username }}" required/>
            </div>

            <div class="form-align">
                <label for="password">Pwd :</label>
                <input type="password" id="password" name="_password" required/>
            </div>

            <input type="hidden" name="_target_path" value="/private" />
            <input type="submit" class="btn btn-primary" value="Connexion">
        </form>

Any idea?

Thanks

Kev
  • 171
  • 2
  • 19

1 Answers1

0

You should at first step check request method and check data if request's method == 'POST'

jamek
  • 792
  • 10
  • 20
  • I have add this but if I write an incorrect login the error message don't appear. – Kev Aug 04 '13 at 10:23