Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- include_once("config.php");
- include_once("includes/functions.php");
- //print_r($_GET);die;
- if(isset($_REQUEST['code'])){
- $gClient->authenticate();
- $_SESSION['token'] = $gClient->getAccessToken();
- header('Location: ' . filter_var($redirect_url, FILTER_SANITIZE_URL));
- }
- if (isset($_SESSION['token'])) {
- $gClient->setAccessToken($_SESSION['token']);
- }
- if ($gClient->getAccessToken()) {
- $userProfile = $google_oauthV2->userinfo->get();
- //DB Insert
- //$gUser->setApprovalPrompt ("auto");
- $gUser = new Users();
- $email = $_SESSION['google_data']['email'];
- $user = strstr($email, '@', true);
- $gUser->checkUser('google',$userProfile['id'],$user,$userProfile['given_name'],$userProfile['family_name'],$userProfile['email'],$userProfile['gender'],$userProfile['locale'],$userProfile['link'],$userProfile['picture']);
- $_SESSION['google_data'] = $userProfile; // Storing Google User Data in Session
- header("location: feed.php");
- $_SESSION['token'] = $gClient->getAccessToken();
- } else {
- $authUrl = $gClient->createAuthUrl();
- }
- ?>
- <?php
- class Users {
- public $tableName = 'users';
- function __construct(){
- //database configuration
- $dbServer = 'localhost'; //Define database server host
- $dbUsername = 'root'; //Define database username
- $dbPassword = ''; //Define database password
- $dbName = 'live'; //Define database name
- //connect databse
- $con = mysqli_connect($dbServer,$dbUsername,$dbPassword,$dbName);
- if(mysqli_connect_errno()){
- die("Failed to connect with MySQL: ".mysqli_connect_error());
- }else{
- $this->connect = $con;
- }
- }
- function checkUser($oauth_provider,$oauth_uid,$user,$fname,$lname,$email,$gender,$locale,$link,$picture){
- $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));
- if(mysqli_num_rows($prevQuery) > 0){
- $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));
- }else{
- $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));
- }
- $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));
- $result = mysqli_fetch_array($query);
- return $result;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement