<?php
require_once('config.php');

if(isset($_SESSION['id'])){
  redirect('admin/');
  exit;
}
?>
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="utf-8">
<title>Login | SGPPBN</title>
<meta name="viewport" content="width=device-width, initial-scale=1">

<link rel="stylesheet" href="<?php echo base_url ?>dist/css/adminlte.css">
<script src="<?php echo base_url ?>plugins/jquery/jquery.min.js"></script>
</head>

<body class="hold-transition login-page">


<div class="login-box">
  <div class="login-logo"><b>SGPPBN</b></div>

  <div class="card">
    <div class="card-body login-card-body">
      <form id="login-form">
        <div class="form-group">
          <input type="email" name="email" class="form-control" placeholder="Correo" required>
        </div>
        <div class="form-group">
          <input type="password" name="password" class="form-control" placeholder="Contraseña" required>
        </div>
        <button class="btn btn-danger btn-block" type="submit">Ingresar</button>
      </form>
    </div>
  </div>
</div>

<script>
$('#login-form').submit(function(e){
  e.preventDefault();

  $.ajax({
    url: "<?php echo base_url ?>classes/Login.php?f=login",
    method: "POST",
    data: $(this).serialize(),
    dataType: "json",
    success: function(resp){
      if(resp.status === 'success'){
        window.location.href = "<?php echo base_url ?>admin/";
      } else {
        alert(resp.msg);
      }
    },
    error:function(){
      alert("Error conexión");
    }
  });
});
</script>

</body>
</html>
