public function login()
{
$this->load->helper('form');
$this->load->library('form_validation');
$validation_rules = array(
array(
'field' => 'username',
'label' => lang('login_email'),
'rules' => array(
'trim',
'valid_email'
)
),
array(
'field' => 'password',
'label' => lang('login_password'),
'rules' => array(
'trim',
'required',
array('validate_auth', array( $this, '_validate_auth' ) )
)
)
);
$this->form_validation->set_rules( $validation_rules );
if( $this->form_validation->run() === TRUE )
{
return TRUE;
}
return FALSE;
}
// --------------------------------------------------------------
public function _validate_auth()
{
$user_email = $this->input->post('username');
$user_password = $this->input->post('password');
if( empty($user_email) OR empty($user_password) )
{
$this->form_validation->set_message('validate_auth', lang('error_missing_fields'));
return FALSE;
}
if( $auth_data = $this->auth_model->get_auth_data( $user_email ) )
{
if( $auth_data->banned === '1' )
{
$this->form_validation->set_message('validate_auth', lang('error_username_password'));
return FALSE;
}
if( ! $this->check_password( $auth_data->passwd, $user_password ) )
{
$this->form_validation->set_message('validate_auth', lang('error_username_password'));
}
else
{
// Setup redirection if redirect required
$this->redirect_after_login();
// Set session cookie and remember me
$this->maintain_state( $auth_data );
// Send the auth data back to the controller
return TRUE;
}
}
else
{
$this->form_validation->set_message('validate_auth', lang('error_username_password'));
}
return FALSE;
}