<?php

class AutenticacionController extends BaseController {

  /*
  |--------------------------------------------------------------------------
  | Default Home Controller
  |--------------------------------------------------------------------------
  |
  | You may wish to use controllers instead of, or in addition to, Closure
  | based routes. That's great! Here is an example controller method to
  | get you started. To route to this controller, just add the route:
  |
  |	Route::get('/', 'HomeController@showWelcome');
  |
  */

  public function login()
  {
    $error = '';
    $info = '';
    $usuario = '';

    if (Auth::check()) {
      return Redirect::to('/');
    }

    if(Input::all()){
      $usuario = Input::get('usuario');
      $password = Input::get('password');
      if (Auth::attempt(array('usuario' => $usuario, 'password' => $password)))
      {
        return Redirect::intended('/');
      }
      $error = 'Usuario y/o contraseña inválida.';
    }


    $parametros = array(
                    'usuario'=>$usuario,
                    'info' => $info,
                    'error' => $error
                  );
    return View::make('login')->with($parametros);
  }

  public function logout(){
    Auth::logout();
    return Redirect::to('login');
  }

}
