I have this model and control that verifies and validates registered users in the tb_users table of the database. I need a script that checks whether the user is 0 or 1 in the nv_level column. If the user is equal to 0 it directs to redirect('usuario/home', 'refresh');
if it is equal to 1 directs to redirect('admin/home', 'refresh');
Below is the code Model and Controller .
- > Model
class Login_model extends CI_Model {
function ValidaLogin() {
$this->db->where('hl_email', $this->input->post('email'));
$this->db->where('pw_password', md5($this->input->post('senha')));
$query = $this->db->get('tb_user');
if ($query->num_rows == 1) {
return true;
}
}
}
- > controller
public function valida() {
$this->load->model('login_model'); //Carrega o model
$query = $this->login_model->ValidaLogin(); //Chama a função da Model que checa o usuário no BD
if ($query) { //Se o Usuário e senha existir no mesmo registro...
$data = array(
'login' => $this->input->post('email'),
'is_logged_in' => true
);
$this->session->set_userdata($data);
redirect('usuario/home', 'refresh');
} else { // incorreto username ou password
$info['msg'] = "Informações incorretas";
$this->load->view('header_html');
$this->load->view('header_view');
$this->load->view('login/login_view', $info);
$this->load->view('footer_view');
$this->load->view('footer_html');
}
}