public function login()
 {
     //login
     session_start();
     if (isset($_SESSION['user_id'])) {
         header('Location:  index.php?ctl=listar');
     }
     if ($_SERVER['REQUEST_METHOD'] == 'POST') {
         $m = new UsuarioModel(Config::$mvc_bd_nombre, Config::$mvc_bd_usuario, Config::$mvc_bd_clave, Config::$mvc_bd_hostname);
         //coneccion al modelo
         $user_kai = $_POST['usuario_kai'];
         $password_kai = $_POST['password_kai'];
         $response = $m->login($user_kai, $password_kai);
         print_r($response);
         if (count($response) == 1) {
             $user = $response[0];
             $_SESSION['user_id'] = $user["id"];
             $_SESSION['user_name'] = $user["name"];
             //print_r($_SESSION);
             if (isset($_SESSION['user_id'])) {
                 header('Location:  index.php?ctl=listar');
                 //print_r($_SESSION);
             } else {
                 echo "sin user id";
                 //print_r($_SESSION);
                 require __DIR__ . '/templates/login.php';
             }
         } else {
             echo "los datos son incorrectos";
             require __DIR__ . '/templates/login.php';
         }
     } else {
         require __DIR__ . '/templates/login.php';
     }
 }
Example #2
0
 public function processLogin()
 {
     /** o login é executado somente se existir um input
      * e se receber um token do formulário */
     if (Input::exists()) {
         //echo var_dump(Token::check(Input::get('token'))) . Input::get('token');
         //if (Token::check(Input::get('token'))) {
         $usuarioDTO = new UsuarioDTO();
         $this->usuarioModel->setDTO($usuarioDTO);
         $usuario = filter_var(Input::get('usuario'), FILTER_SANITIZE_STRING);
         $senha = filter_var(Input::get('senha'), FILTER_SANITIZE_STRING);
         if ($this->usuarioModel->login($usuario, $senha)) {
             Redirect::to(SITE_URL);
         } else {
             Session::flash('msg', 'Falha no login!', 'danger');
         }
         //}
     }
 }