Ir para conteúdo

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

eduehi

Tela de Login não funciona Alert

Recommended Posts

Bom dia Pessoal, estou fazendo uma tela de login, mas não apresenta o Alert em caso de falha no login. Segue meu código:

<?php

class Acesso{
      public function run(){
          
          $html = '';

          Session::setValue('erro','');

          switch (App::getAction()) {
              case 'logout':
                  $this->logout();
                  break;
          
              case 'validar':
                  $this->validar();
                  break;

              default:
                  $html = $this->login();
                  break;
          }
          
          return $html;
          
      }
      public function login(){
      
            $html_login= new Html();
            $html=$html_login->load( 'view/login.html');
            
            return $html;
          
      }
     
      public function validar(){
     
          $dados = Connection::select( "SELECT login,senha,departamento_id FROM usuario WHERE login='".$_POST['usuario']."'" );
          Connection::close();
          
          foreach( $dados as $reg):
              if($_POST['senha']==$reg['senha']):
                    Session::setValue('logado',true);
                    Session::setValue('departamento',$reg['departamento_id']);
              else:
                    //Session::setValue('erro');
                    echo  "<script>alert('Dados inválidos!);</script>";
                    //header('location: index.php');
              endif;
          endforeach;
          
          header( 'Location: '.URL ) ;
          
      }
      
      public function logout(){
             
          Session::setValue('logado',false);
          header( 'Location: '.URL ) ;
          
      }
      
}

Compartilhar este post


Link para o post
Compartilhar em outros sites


<?php

 

class Acesso{

public function run(){

 

$html = '';

 

Session::setValue('erro','');

 

switch (App::getAction()) {

case 'logout':

$this->logout();

break;

 

case 'validar':

$this->validar();

break;

 

default:

$html = $this->login();

break;

}

 

return $html;

 

}

public function login(){

 

$html_login= new Html();

$html=$html_login->load( 'view/login.html');

 

return $html;

 

}

 

public function validar(){

 

$dados = Connection::select( "SELECT login,senha,departamento_id FROM usuario WHERE login='".$_POST['usuario']."'" );

Connection::close();

 

foreach( $dados as $reg):

if($_POST['senha']==$reg['senha']):

Session::setValue('logado',true);

Session::setValue('departamento',$reg['departamento_id']);

else:

//Session::setValue('erro');

echo "<script>alert('Dados inválidos!');</script>";

//header('location: index.php');

endif;

endforeach;

 

header( 'Location: '.URL ) ;

 

}

 

public function logout(){

 

Session::setValue('logado',false);

header( 'Location: '.URL ) ;

 

}

 

}

Compartilhar este post


Link para o post
Compartilhar em outros sites

Outra coisa. Se estiver usando o header que esta comentado, apaga ele e deixa assim:

 

echo "<script>alert('Dados inválidos!'); location: 'index.php';</script>";

Ou seja, substitui essas duas linhas debaixo pelo código de cima rs

 

echo "<script>alert('Dados inválidos!');</script>";
//header('location: index.php');

Compartilhar este post


Link para o post
Compartilhar em outros sites

 

Outra coisa. Se estiver usando o header que esta comentado, apaga ele e deixa assim:

echo "<script>alert('Dados inválidos!'); location: 'index.php';</script>";

Ou seja, substitui essas duas linhas debaixo pelo código de cima rs

echo "<script>alert('Dados inválidos!');</script>";
//header('location: index.php');

Nada de funcionar rs

:(

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.