Advertisement
Guest User

Untitled

a guest
Feb 2nd, 2016
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.20 KB | None | 0 0
  1. include_once("config.php");
  2. include_once("includes/functions.php");
  3.  
  4. //print_r($_GET);die;
  5.  
  6. if(isset($_REQUEST['code'])){
  7. $gClient->authenticate();
  8. $_SESSION['token'] = $gClient->getAccessToken();
  9. header('Location: ' . filter_var($redirect_url, FILTER_SANITIZE_URL));
  10. }
  11.  
  12. if (isset($_SESSION['token'])) {
  13. $gClient->setAccessToken($_SESSION['token']);
  14. }
  15.  
  16. if ($gClient->getAccessToken()) {
  17. $userProfile = $google_oauthV2->userinfo->get();
  18. //DB Insert
  19. //$gUser->setApprovalPrompt ("auto");
  20. $gUser = new Users();
  21. $email = $_SESSION['google_data']['email'];
  22. $user = strstr($email, '@', true);
  23.  
  24. $gUser->checkUser('google',$userProfile['id'],$user,$userProfile['given_name'],$userProfile['family_name'],$userProfile['email'],$userProfile['gender'],$userProfile['locale'],$userProfile['link'],$userProfile['picture']);
  25. $_SESSION['google_data'] = $userProfile; // Storing Google User Data in Session
  26. header("location: feed.php");
  27. $_SESSION['token'] = $gClient->getAccessToken();
  28. } else {
  29. $authUrl = $gClient->createAuthUrl();
  30. }
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37. ?>
  38.  
  39. <?php
  40.  
  41. class Users {
  42. public $tableName = 'users';
  43.  
  44. function __construct(){
  45. //database configuration
  46. $dbServer = 'localhost'; //Define database server host
  47. $dbUsername = 'root'; //Define database username
  48. $dbPassword = ''; //Define database password
  49. $dbName = 'live'; //Define database name
  50.  
  51. //connect databse
  52. $con = mysqli_connect($dbServer,$dbUsername,$dbPassword,$dbName);
  53. if(mysqli_connect_errno()){
  54. die("Failed to connect with MySQL: ".mysqli_connect_error());
  55. }else{
  56. $this->connect = $con;
  57. }
  58. }
  59.  
  60. function checkUser($oauth_provider,$oauth_uid,$user,$fname,$lname,$email,$gender,$locale,$link,$picture){
  61. $prevQuery = mysqli_query($this->connect,"SELECT * FROM $this->tableName WHERE oauth_provider = '".$oauth_provider."' AND oauth_uid = '".$oauth_uid."'") or die(mysqli_error($this->connect));
  62. if(mysqli_num_rows($prevQuery) > 0){
  63. $update = mysqli_query($this->connect,"UPDATE $this->tableName SET oauth_provider = '".$oauth_provider."', oauth_uid = '".$oauth_uid."',username ='".$user."',fname = '".$fname."', lname = '".$lname."', email = '".$email."', gender = '".$gender."', locale = '".$locale."', picture = '".$picture."', gpluslink = '".$link."', modified = '".date("Y-m-d H:i:s")."' WHERE oauth_provider = '".$oauth_provider."' AND oauth_uid = '".$oauth_uid."'") or die(mysqli_error($this->connect));
  64. }else{
  65. $insert = mysqli_query($this->connect,"INSERT INTO $this->tableName SET oauth_provider = '".$oauth_provider."', oauth_uid = '".$oauth_uid."',username='".$user."', fname = '".$fname."', lname = '".$lname."', email = '".$email."', gender = '".$gender."', locale = '".$locale."', picture = '".$picture."', gpluslink = '".$link."', created = '".date("Y-m-d H:i:s")."', modified = '".date("Y-m-d H:i:s")."'") or die(mysqli_error($this->connect));
  66. }
  67.  
  68. $query = mysqli_query($this->connect,"SELECT * FROM $this->tableName WHERE oauth_provider = '".$oauth_provider."' AND oauth_uid = '".$oauth_uid."'") or die(mysqli_error($this->connect));
  69. $result = mysqli_fetch_array($query);
  70. return $result;
  71. }
  72. }
  73.  
  74. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement