public function index()
{
$this->form_validation->set_rules('username', 'Username', 'trim');
$this->form_validation->set_rules('first_name', 'First name', 'required|trim');
$this->form_validation->set_rules('last_name', 'Last name', 'required|trim');
$this->form_validation->set_rules('telephone', 'Telephone', 'trim');
$this->form_validation->set_rules('email', 'Email', 'required|trim|valid_email|callback_new_email_is_unique');
$this->form_validation->set_rules('new_password', 'New password', 'trim|xss_clean|matches[confirm_new_password]');
$this->form_validation->set_rules('confirm_new_password', 'Confirm new password', 'trim');
$this->form_validation->set_rules('twitter_username', 'Twitter Username', 'trim');
if ($this->form_validation->run() == FALSE):
$this->data['message'] = (validation_errors()) ? validation_errors() : $this->session->flashdata('message');
$this->load->vars($this->data);
$this->load->view('account/index');
else:
$data = array(
'first_name' => $this->input->post('first_name'),
'last_name' => $this->input->post('last_name'),
'telephone' => $this->input->post('telephone'),
'email' => $this->input->post('email'),
'twitter_username' => $this->input->post('twitter_username')
);
if($this->input->post('new_password') != '' && $this->input->post('confirm_new_password') != ''):
$data['password'] = $this->input->post('new_password');
endif;
if($this->ion_auth->update($this->user->id, $data)):
$this->session->set_flashdata('success-message', 'You have successfully updated your details.');
else:
$this->session->set_flashdata('error-message', 'Oops, something went wrong. Please try again.');
endif;
redirect($this->session->flashdata('referrer'), 'location');
endif;
}