I have the following code that checks the userName & userPassword is correct then login but I also want to include another couple checks that are not on the login form but come from the database – userGroup - user/admin & userActive - yes/no. How would I write the login function to take in the vars?
Controller:
public function login()
{
$this->form_validation->set_rules('userName','userName', 'required|valid_email|trim|max_length[99]|xss_clean');
$this->form_validation->set_rules('userPassword','userPassword', 'required|trim|max_length[200]|xss_clean|callback__checkUser');
if($this->form_validation->run() === TRUE) {
// set CLEAN data in the session.
redirect('admin/dashboard');
}
$this->index();
}
}
Model:
function _checkUser(){ // Private function
extract($_POST);
$login = $this->admin_model->check_login($userName,$userPassword,$userGroup,$userEmail,$userActive);
if(! $login){
$this->session->set_flashdata('login_error', TRUE);
$this->form_validation->set_message('_checkUser','Sorry your %s is not correct');
return FALSE;
}else{
$this->session->set_userdata('logged_in', TRUE);
$this->session->set_userdata('userID', $user->id);
$this->session->set_userdata('userName',$user->userName);
$this->session->set_userdata('firstName',$user->userFirstName);
$this->session->set_userdata('lastName'),$user->userLastName;
$this->session->set_userdata('userEmail',$user->userEmail);
$this->session->set_userdata('userGroup'),$user->userGroup;
$this->session->set_userdata('userActive'),$user->userActive;
}
If I understand your question properly you can something like this in your else part
you can have something like this