I am using ion auth for my CI authentication. I got a problem with auto login after registered. I got no problem with the register, all data are inserted and i can get to login with my login form. But it won't redirect to the home page after a user registered.
below is my code. Can anyone take a look?
if ( $this->form_validation->run() == TRUE )
{
//if form validation not false, password var
$username = $this->input->post('email');
$password = $this->input->post('password');
$email = $this->input->post('email');
$additional_data = array(
'first_name' => $this->input->post('first_name'),
'last_name' => $this->input->post('last_name'),
);
}
if ($this->form_validation->run() == TRUE && $this->ion_auth->register($username, $password, $email, $additional_data))
{
//check to see if we are creating the user
//redirect them back to the home page
$this->session->set_flashdata('msg', "User Created");
redirect("auth/home", 'refresh');
}
else
{
$this->session->set_flashdata('msg', validation_errors('<div>','</div>'));
redirect('auth/index','refresh');
}
It is because the user is "registered" but they are not "logged in". You need to manually log them in, after the register, but before you redirect.
if ($this->form_validation->run() == TRUE && $this->ion_auth->register($username, $password, $email, $additional_data))
{
//check to see if we are creating the user
//redirect them back to the home page
$this->session->set_flashdata('msg', "User Created");
// ***DO MANUAL LOGIN HERE WITH ION_AUTH***
redirect("auth/home", 'refresh');
}