Created
December 5, 2017 10:57
-
-
Save AlpeshKatariya/d5594d02a9659b99938dbd4e8cc1e3e3 to your computer and use it in GitHub Desktop.
About CodeIgniter Facebook login controller
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function Facebook(){ | |
$userData = array(); | |
// Check if user is logged in | |
if($this->fb_library->is_authenticated()){ | |
// Get user facebook profile details | |
$userProfile = $this->fb_library->request('get', '/me?fields=id,first_name,last_name,email,gender,locale,picture'); | |
// Preparing data for database insertion | |
$userData['Auth_Provider'] = 'FB'; | |
$userData['Auth_Id'] = $userProfile['id']; | |
$userData['First_Name'] = $userProfile['first_name']; | |
$userData['Last_Name'] = $userProfile['last_name']; | |
$userData['Mobile_No'] = ""; | |
if(isset($userProfile['email'])){ | |
$userData['Email_Id'] = $userProfile['email']; | |
//$userData['Hello'] = "Yes"; | |
}else{ | |
$userData['Email_Id'] = ""; | |
//$userData['Hello'] = "No"; | |
} | |
$userData['Password'] = ""; | |
$userData['Pwd_Status'] = mt_rand(100000, 999999); | |
//$userData['gender'] = $userProfile['gender']; | |
//$userData['locale'] = $userProfile['locale']; | |
//$userData['profile_url'] = 'https://www.facebook.com/'.$userProfile['id']; | |
$userData['Picture_Url'] = $userProfile['picture']['data']['url']; | |
// Insert or update user data | |
$userID = $this->Social_Model->checkUser($userData); | |
$this->session->set_userdata('Ses_Name', $userProfile['first_name']); | |
// Check user data insert or update status | |
if(!empty($userID)){ | |
$data['userData'] = $userData; | |
$this->session->set_userdata('userData',$userData); | |
}else{ | |
$data['userData'] = array(); | |
} | |
// Get logout URL | |
$data['logoutUrl'] = $this->fb_library->logout_url(); | |
$this->session->set_userdata('Fb_LogoutUrl', $this->fb_library->logout_url()); | |
}else{ | |
$fbuser = ''; | |
// Get login URL | |
$data['authUrl'] = $this->fb_library->login_url(); | |
} | |
return $data; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment