I am developing a system to practice but I was generated a problem with the Login, since using a validation script using AJAX sending via the GET method a variable to a switch and a conditional did not achieve the desired effect since pressing the submit redirects to the system page so the user is non-existent, ie no validation exists. here is the code I am using.
//Funcion para verify system access
public function verificar($login,$password){
$sql="SELECT idusuario,nombre,tipo_documento,num_documento,tlf,email,cargo,imagen,login FROM usuario WHERE login='$login' AND password='$password' AND condicion='1'";
return executeQuery($sql);
}
Case del SWITCH
case 'verificar':
$logina=$_POST['logina'];
$passworda=$_POST['passworda'];
//Hash SHA256 en la contraseña
$passwordhash=hash("SHA256",$passworda);
$rspta=$usuario->verificar($logina, $passwordhash);
$fetch=$rspta->fetch_object();
if (isset($fetch))
{
//Declaramos las variables de sesión
$_SESSION['idusuario']=$fetch->idusuario;
$_SESSION['nombre']=$fetch->nombre;
$_SESSION['imagen']=$fetch->imagen;
$_SESSION['login']=$fetch->login;
}
echo json_encode($fetch);
break;
Validation Script
$("#frmAcceso").on('submit',function(e)
{
e.preventDefault();
logina=$("#logina").val();
passworda=$("#passwora").val();
$.post("ajax/usuario.php?op=verificar",
{"logina":logina,"passworda":passworda},
function(data)
{
if (data!="null")
{
$(location).attr("href","views/pages/categoria.php");
}
else
{
bootbox.alert("Usuario y/o Password incorrectos");
}
});
})
Form HTML
<form method="post" id="frmAcceso">
<div class="form-group has-feedback">
<input type="text" id="logina" name="logina" class="form-control" placeholder="Usuario" required>
<span class="fa fa-user form-control-feedback"></span>
</div>
<div class="form-group has-feedback">
<input type="password" id="passworda" name="passworda" class="form-control" placeholder="Password" required>
<span class="fa fa-key form-control-feedback"></span>
</div>
<div class="row">
<div class="col-xs-8">
</div>
<!-- /.col -->
<div class="col-xs-4">
<button type="submit" class="btn btn-primary btn-block btn-flat">Ingresar</button>
</div>
<!-- /.col -->
</div>
</form>
pressing the submit button sends me to 'categoria.php' no matter what data is put in the form I already probre that the ** Case ** Verify works correctly, since it returns data to me or null depending on the result, but in my JS the Data field receives information that is not ** null ** always and this is what causes the apparently redirection