<?php



class Control_acceso {



  public function __construct() {

      $this->CI = & get_instance();

      $controller = $this->CI->router->fetch_class();

      $method = $this->CI->router->fetch_method();

      $is_login = $this->CI->session->userdata('is_login');

      if ($controller != 'login' && !$is_login) {

          redirect('login');

      } else if ($controller === 'login' && $is_login && $method != 'salir') {

          redirect('inicio');

      }

  }



  public function crearSession() {

    $password = sha1($this->CI->input->post('password'));

    $passwordF = hash('sha256', $password);

    $query = $this->CI->db

            ->where('usuario', $this->CI->input->post('usuario'))

            ->where('password', $passwordF)

            ->where('estado', '0')

            ->get('usuario')

            ->row();

    if ($query) {

        $data = array(

            'is_login' => TRUE,

            'usuario' => $query->id,

            'empresa' => $query->empresa,

            'perfil' => $query->perfil,

        );

        $this->CI->session->set_userdata($data);

        return TRUE;

    } else {

        return FALSE;

    }

  }



}

