I have authentication up and running in CodeIgnitor using Ion Auth, seems to be a great library with all the functionality I need. But I want to create an AJAX login, using jQuery. Basically to enhance the functionality / degrade gracefully when javascript is or is not present.
I have no idea how to do it so that on subsequent pages where Ion Auth checks the logged in status it will all work properly.
Here's what I have so far:
--
CONTROLLER
public function js_login()
{
if( $this->ion_auth->login($this->input->post('identity'),
$this->input->post('password'),
$this->input->post('remember')))
{
$result = "Login Details Correct";
}
else
{
$result = "Login Details incorrect";
}
$array = array( "result" => $result );
echo json_encode($array);
}
--
SCRIPT
$("#login").submit(function(event) {
event.preventDefault();
$.post( "/auth/js_login", $(this).serialize(), function(data){
// Set the cookie somehow
alert(data.result);
}, "json");
});
--
So I basically need to know how to get the session data that is normally set by Ion Auth and set it using jQuery. After that I can redirect to the appropriate page.