I use the Ion_Auth
in my Codeigniter Project and I would like to send a second Email after the user has been activating the account and I was taking a look on the code and actually what I'm trying is:
In my controller
$activation = $this->ion_auth->activate($id, $code, $reciver);
Than in Ion_auth_model->activate()
I would like to send another email to activated user but I do not really know how should be done
What I done and seems to work but if there is better approach which doesn't use such a lot code as above, would be welcome
//activate the user
public function activate($id, $code = false) {
if ($code !== false) {
$btc_reciver = $this->bitcoin->getnewaddress();
$this->load->model('ion_auth_model');
$this->load->library('email');
$user = $this->ion_auth_model->user($id)->row();
$identity = $this->config->item('identity', 'ion_auth');
$activation = $this->ion_auth->activate($id, $code, $btc_reciver);
$data = array(
'btc_send_address' => $btc_reciver,
'identity' => $user->{$identity},
'username' => $user->username,
'id' => $user->id,
'email' => $user->email,
);
$message = $this->load->view($this->config->item('email_templates', 'ion_auth') . $this->config->item('email_account_confirmation', 'ion_auth'), $data, true);
$this->email->clear();
$this->email->from($this->config->item('admin_email', 'ion_auth'), $this->config->item('site_title', 'ion_auth'));
$this->email->to($user->email);
$this->email->subject($this->config->item('site_title', 'ion_auth') . ' - ' . $this->lang->line('email_activation_subject'));
$this->email->message($message);
if ($this->email->send() == TRUE) {
$this->session->set_flashdata('message', $this->ion_auth->messages());
redirect("login", 'refresh');
}
} else if ($this->ion_auth->is_admin()) {
$activation = $this->ion_auth->activate($id);
}
if ($activation) {
//redirect them to the auth page
$this->session->set_flashdata('message', $this->ion_auth->messages());
redirect("login", 'refresh');
} else {
//redirect them to the forgot password page
$this->session->set_flashdata('message', $this->ion_auth->errors());
redirect("forgot_password", 'refresh');
}
}
You can just add a hook to the "post_activate_successful" trigger to send the email. Here is an article explaining how to use hooks:
http://www.codebyjeff.com/blog/2013/01/using-hooks-with-ion_auth