Obtain user data logged with codeigniter and mysql

0

I am doing my first project in codeigniter, and I have a question with the login of the application, what I need is to obtain the data of the logged in user (with his RUT and Password) to show them on the homepage. The driver is the following:

public function Index(){
    $usu_rut = $this->session->userdata('usu_rut');
            switch ($this->session->userdata('per_nombre')) {
        case '':
    $data['titulo']="Inicio de Sesión";
    $this->load->view('login',$data);
            break;
        case 'Administrador':
            redirect(base_url().'administrador');
            break;
        case 'Postulante':
            redirect(base_url().'postulante');
            break;
        case 'Evaluador':
            redirect(base_url().'evaluador');
            break;
        default:
    $data['titulo']="Inicio de Sesión";
    $this->load->view('login',$data);
            break;
    }

}      

public function validar(){
    $datos = array(
                    'USU_RUT'   =>  $this->input->post('USU_RUT'),
                    'USU_PASS'  =>  md5($this->input->post('USU_PASS'))
                    );
    $data = $this->m_login->get_data($datos['USU_RUT'],$datos['USU_PASS']);
            if ($data) {
            $this->session->set_userdata('usu_rut',$data['USU_RUT']);
            $this->session->set_userdata('usu_nombre1',$data['USU_NOMBRE1']);
            $this->session->set_userdata('per_nombre',$data['PER_NOMBRE']);
            $this->index();
        }else{
            $this->session->set_flashdata('msg_error', 'Error, intente nuevamente');
            $data['titulo']="Inicio de Sesión";
            $this->load->view('login',$data);
        }
}


The model is as follows:

public function get_data($USU_RUT,$USU_PASS){
    $this->db->select('*');
    $this->db->from('usuario_usu');
    $this->db->where('USU_RUT', $USU_RUT);
    $this->db->where('USU_PASS', $USU_PASS);
    $this->db->join('perfiles_per', 'perfiles_per.PER_ID = usuario_usu.PER_ID');
    if ($query=$this->db->get()) {
        return $query->row_array();
    }else{
        return false;
    }
}

When making the query to the bd it obtains the user profile, and compares the profile with the switch function and redirects it to another controller with its permissions for the profile, this the administrator's driver:

public function Index(){;
    $data['titulo'] = "Pagina Principal";
    $this->load->view('plantillas/Header',$data);
    $this->load->view('inicio');
}

Any help I appreciate.

    
asked by Jehyson 22.11.2017 в 06:51
source

0 answers