[eluser]Maximilian Schoening[/eluser]
Hi,
I'm writing my own auth library at the moment and ran into a problem field validation. I have my own callbacks defined however they are ignored during validation. Can somebody tell me why? Here is the login function inside my Auth.php library. I call the login function inside my controller login().
Here's the code:
Code:
/** ----------------------------------------------------------------------
* Login
**/
function login() {
$this->CI =& get_instance();
$this->CI->load->library('form_validation');
$this->CI->load->helper('form');
$this->CI->form_validation->set_rules('email', 'Email', 'trim|required|valid_email|callback__login_validate_email|callback__login_validate_password');
$this->CI->form_validation->set_rules('password', 'Password', 'trim|required');
if ($this->CI->form_validation->run() == FALSE) {
$this->CI->view('user/login');
}
else {
$user = $this->get_user(set_value('email'));
$this->CI->session->sess_destroy();
$this->CI->session->sess_create();
$user_data = array(
'user_id' => $user['id'],
'user' => $user['email'],
'logged_in' => TRUE
);
$this->CI->session->set_userdata($user_data);
redirect('user/profile');
}
}
function _login_validate_email($email) {
return $this->check_email($email);
}
function _login_validate_password($password) {
if (set_value('email') == '' OR $password == '') {
return TRUE;
}
else {
return $this->check_password(set_value('email'), $password);
}
}
// -----------------------------------------------------------------------
/** ----------------------------------------------------------------------
* Tools
**/
function check_email($email) {
$query = $this->CI->db->get_where('users', array('email' => $email));
if ($query->num_rows() == 0) {
return FALSE;
}
else {
return TRUE;
}
}
function check_password($email, $password) {
$this->CI->load->library('encrypt');
$query = $this->CI->db->get_where('users', array('email' => $email));
if ( ! $password != $this->encrypt->decode($query->row->password)) {
return FALSE;
}
else {
return TRUE;
}
}
function get_user($email) {
$query = $this->CI->db->get_where('users', array('email' => $email));
return $query->row_array();
}
// -----------------------------------------------------------------------
Thanks,
Max