Invalid login message always appears in Cakephp

Asked

Viewed 378 times

1

When I log in to my login page, the warning message appears that the user or passwords are invalid, but this should only appear after pressing the login button. There’s no way around this?

My view:

    <div class="large-4 columns" style="margin-left: 15px;">
     <div class="row">
     <div class="users form">
       <span class="login_form">
        <?php echo $this->Session->flash(); ?></span>
   <?php echo $this->Form->create('User');?>
    <fieldset>
        <?php echo $this->Form->input('email');
        echo $this->Form->input('password');
    ?>
    </fieldset>
<?php echo $this->Form->submit('Login', array('class' => 'button'));?>
</div>
</div>

My action: public Function login() {

    if ($this->Auth->login()) {
        $this->redirect($this->Auth->redirect());
    } else {
        $this->Session->setFlash(__('Username ou password inválidos!'));
    }
}
  • I have never worked with Cakephp, but it seems to me that he is already doing Ubmit when he loads the page, and since the fields are empty and the user is invalid it is an error. Now, I can’t give you a solution :/

  • I think so too, but I don’t know why you’re doing Submit right away. It’s illogical.

1 answer

4


It is because your action is trying to authenticate as soon as it loads.

// Verifica o tipo de requisição, se for POST(form submit) tenta logar.
if($this->request->is('post')) {
    if ($this->Auth->login()) {
        $this->redirect($this->Auth->redirect());
    } else {
        $this->Session->setFlash(__('Username ou password inválidos!'));
    }
}
  • @Ricardo Costa, this answer answered the question?

  • Thanks Marcelo. Yes, it worked!

  • @Ricardocosta brand "accept answer" to finalize the question please... ;)

  • odne do it?

  • In the upper left corner of the answer, where the number 4 is, you pass the mouse further down and click on the green "old".

Browser other questions tagged

You are not signed in. Login or sign up in order to post.