daily pastebin goal
51%
SHARE
TWEET

Untitled

a guest Feb 4th, 2016 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php ini_set('display_errors', 1);
  2.     error_reporting(E_ALL ^ E_NOTICE); ?>
  3.  
  4.  
  5.     <?php
  6.  
  7.     include_once("config.php");
  8.     include_once("includes/functions.php");
  9.  
  10.     //print_r($_GET);die;
  11.  
  12.     if(isset($_REQUEST['code'])){
  13.       $gClient->authenticate();
  14.       $_SESSION['token'] = $gClient->getAccessToken();
  15.       header('Location: ' . filter_var($redirect_url, FILTER_SANITIZE_URL));
  16.     }
  17.  
  18.     if (isset($_SESSION['token'])) {
  19.       $gClient->setAccessToken($_SESSION['token']);
  20.     }
  21.  
  22.  
  23.  
  24.     if ($gClient->getAccessToken()) {
  25.       $userProfile = $google_oauthV2->userinfo->get();
  26.       //DB Insert
  27.       //$gUser->setApprovalPrompt ("auto");
  28.  
  29.       $gUser = new Users();
  30.       // As of PHP 5.3.0
  31.  
  32.       $gUser->checkUser('google',$userProfile['id'],$userProfile['given_name'],$userProfile['family_name'],$userProfile['email'],$userProfile['gender'],$userProfile['locale'],$userProfile['link'],$userProfile['picture'],$username);
  33.       $_SESSION['google_data'] = $userProfile; // Storing Google User Data in Session
  34.       header("location: feed.php");
  35.  
  36.       $_SESSION['token'] = $gClient->getAccessToken();
  37.     } else {
  38.       $authUrl = $gClient->createAuthUrl();
  39.     }
  40.  
  41.       $email  = $_SESSION['google_data']['email'];
  42.       $user = strstr($email, '@', true);
  43.       $username = $user;
  44. ?>
  45.    
  46. <?php ini_set('display_errors', 1);
  47. error_reporting(E_ALL ^ E_NOTICE); ?>
  48.  
  49. <?php
  50.  session_start();
  51. class Users {
  52.     public $tableName = 'users';
  53.  
  54.  function __construct(){
  55.         //database configuration
  56.         $dbServer = 'localhost'; //Define database server host
  57.         $dbUsername = 'root'; //Define database username
  58.         $dbPassword = ''; //Define database password
  59.         $dbName = 'livelor'; //Define database name
  60.  
  61.         //connect databse
  62.         $con = mysqli_connect($dbServer,$dbUsername,$dbPassword,$dbName);
  63.         if(mysqli_connect_errno()){
  64.             die("Failed to connect with MySQL: ".mysqli_connect_error());
  65.         }else{
  66.             $this->connect = $con;
  67.         }
  68.     }
  69.  
  70.     function checkUser($oauth_provider,$oauth_uid,$fname,$lname,$email,$gender,$locale,$link,$picture,$username){
  71.         $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));
  72.         if(mysqli_num_rows($prevQuery) > 0){
  73.             $update = mysqli_query($this->connect,"UPDATE $this->tableName SET oauth_provider = '".$oauth_provider."', oauth_uid = '".$oauth_uid."' ,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));
  74.         }else{
  75.             $insert = mysqli_query($this->connect,"INSERT INTO $this->tableName SET oauth_provider = '".$oauth_provider."', oauth_uid = '".$oauth_uid."', 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")."' ,  username='".$username."' ") or die(mysqli_error($this->connect));
  76.         }
  77.  
  78.         $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));
  79.         $result = mysqli_fetch_array($query);
  80.         return $result;
  81.  
  82.     }
  83. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top