[eluser]federico_jacobi[/eluser]
Did the existing user today for Facebook and works great. Dacus's code is absolutely correct, but there are a few nuances:
- In the fb login button you need to add "email" to the perms, otherwise you cannot get the user email "directly". You can always get it via auth_other/fill_user_info but I find it complicated and defeats the purpose of the easy FB login.
- As far as i could tell, oAuth (twitter) doesn't return user email ... you HAVE to go through auth_other/fill_user_info ... don't know about google.
To do it modify auth_other/fb_signin and look for (this tells you if the users is ISN'T the db with a Facebook id, else fake tankauthlogin):
Code:
if( sizeof($user) == 0 )
{
redirect('auth_other/fill_user_info', 'refresh');
}
replace with
Code:
if( sizeof($user) == 0 )
{
$user = $this->user_model->get_user_by_email($fb_user['email']); //Notice the need for email perms
if (isset($user[0])) { // IF USER EXISTS UPDATE DB
$this->user_model->update_facebook_user_profile($user_id, $fb_user['id']);
// Now fake a tank_auth login
$this->session->set_userdata(array(
'user_id' => $user[0]->id,
'username' => $user[0]->username,
'status' => ($user[0]->activated == 1) ? STATUS_ACTIVATED : STATUS_NOT_ACTIVATED));
$this->users->update_login_info(
$user[0]->id,
$this->config->item('login_record_ip', 'tank_auth'),
$this->config->item('login_record_time', 'tank_auth'));
redirect('auth', 'refresh');
}
else {
// if it doesn't exist create a new user maybe redirect ... up to you
}
} else {
// Original code here ... means the FB user exists so fake tankauth login and enjoy life
// any new users the register after you install the fblogin should be ok
}
Notice that this works for facebook ... for twitter and google other minor modifications need to happend ... but the idea is the same.