Welcome Guest, Not a member yet? Register   Sign In
Tank Auth with Facebook Connect Authentication
#32

[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.


Messages In This Thread
Tank Auth with Facebook Connect Authentication - by El Forum - 03-21-2011, 09:54 PM
Tank Auth with Facebook Connect Authentication - by El Forum - 03-22-2011, 08:36 AM
Tank Auth with Facebook Connect Authentication - by El Forum - 03-22-2011, 05:44 PM
Tank Auth with Facebook Connect Authentication - by El Forum - 03-23-2011, 01:06 PM
Tank Auth with Facebook Connect Authentication - by El Forum - 03-23-2011, 01:08 PM
Tank Auth with Facebook Connect Authentication - by El Forum - 03-23-2011, 05:03 PM
Tank Auth with Facebook Connect Authentication - by El Forum - 03-24-2011, 04:04 AM
Tank Auth with Facebook Connect Authentication - by El Forum - 03-24-2011, 09:40 AM
Tank Auth with Facebook Connect Authentication - by El Forum - 03-25-2011, 04:44 PM
Tank Auth with Facebook Connect Authentication - by El Forum - 03-26-2011, 11:20 PM
Tank Auth with Facebook Connect Authentication - by El Forum - 03-28-2011, 07:50 PM
Tank Auth with Facebook Connect Authentication - by El Forum - 03-28-2011, 09:12 PM
Tank Auth with Facebook Connect Authentication - by El Forum - 03-28-2011, 09:14 PM
Tank Auth with Facebook Connect Authentication - by El Forum - 04-15-2011, 09:13 AM
Tank Auth with Facebook Connect Authentication - by El Forum - 04-15-2011, 08:32 PM
Tank Auth with Facebook Connect Authentication - by El Forum - 04-16-2011, 06:16 PM
Tank Auth with Facebook Connect Authentication - by El Forum - 04-17-2011, 04:15 AM
Tank Auth with Facebook Connect Authentication - by El Forum - 04-20-2011, 07:38 AM
Tank Auth with Facebook Connect Authentication - by El Forum - 04-21-2011, 07:32 AM
Tank Auth with Facebook Connect Authentication - by El Forum - 04-21-2011, 08:11 AM
Tank Auth with Facebook Connect Authentication - by El Forum - 05-05-2011, 05:42 PM
Tank Auth with Facebook Connect Authentication - by El Forum - 05-05-2011, 06:18 PM
Tank Auth with Facebook Connect Authentication - by El Forum - 05-06-2011, 08:37 AM
Tank Auth with Facebook Connect Authentication - by El Forum - 05-19-2011, 02:40 AM
Tank Auth with Facebook Connect Authentication - by El Forum - 05-19-2011, 02:36 PM
Tank Auth with Facebook Connect Authentication - by El Forum - 05-19-2011, 11:24 PM
Tank Auth with Facebook Connect Authentication - by El Forum - 05-21-2011, 01:35 AM
Tank Auth with Facebook Connect Authentication - by El Forum - 05-21-2011, 01:58 AM
Tank Auth with Facebook Connect Authentication - by El Forum - 05-26-2011, 12:26 PM
Tank Auth with Facebook Connect Authentication - by El Forum - 05-27-2011, 02:39 AM
Tank Auth with Facebook Connect Authentication - by El Forum - 05-27-2011, 03:15 PM
Tank Auth with Facebook Connect Authentication - by El Forum - 05-28-2011, 08:20 PM
Tank Auth with Facebook Connect Authentication - by El Forum - 05-31-2011, 02:18 PM
Tank Auth with Facebook Connect Authentication - by El Forum - 06-06-2011, 08:50 AM
Tank Auth with Facebook Connect Authentication - by El Forum - 06-07-2011, 05:52 PM
Tank Auth with Facebook Connect Authentication - by El Forum - 06-09-2011, 02:04 PM
Tank Auth with Facebook Connect Authentication - by El Forum - 06-09-2011, 06:25 PM
Tank Auth with Facebook Connect Authentication - by El Forum - 06-09-2011, 07:45 PM
Tank Auth with Facebook Connect Authentication - by El Forum - 06-10-2011, 07:22 AM
Tank Auth with Facebook Connect Authentication - by El Forum - 06-10-2011, 07:28 AM
Tank Auth with Facebook Connect Authentication - by El Forum - 06-13-2011, 02:29 AM
Tank Auth with Facebook Connect Authentication - by El Forum - 06-13-2011, 07:44 AM
Tank Auth with Facebook Connect Authentication - by El Forum - 06-13-2011, 08:06 AM
Tank Auth with Facebook Connect Authentication - by El Forum - 06-14-2011, 08:43 AM
Tank Auth with Facebook Connect Authentication - by El Forum - 06-21-2011, 01:05 PM
Tank Auth with Facebook Connect Authentication - by El Forum - 06-22-2011, 07:13 AM
Tank Auth with Facebook Connect Authentication - by El Forum - 06-22-2011, 10:01 AM
Tank Auth with Facebook Connect Authentication - by El Forum - 06-22-2011, 11:40 PM
Tank Auth with Facebook Connect Authentication - by El Forum - 06-22-2011, 11:52 PM
Tank Auth with Facebook Connect Authentication - by El Forum - 06-28-2011, 01:06 PM
Tank Auth with Facebook Connect Authentication - by El Forum - 07-22-2011, 01:37 PM
Tank Auth with Facebook Connect Authentication - by El Forum - 08-04-2011, 02:52 PM
Tank Auth with Facebook Connect Authentication - by El Forum - 02-21-2012, 09:26 AM



Theme © iAndrew 2016 - Forum software by © MyBB