view twitter/twitterLogin.php @ 43:dbc006408d2b

ASSUMES we have SetEnv PHP_VALUE "include_path =.:/var/test/private:/var/test/ywww:/usr/share/php" in apache2/.../test.conf use dl(...) for debug logging, defined in dlog.php use doAmazonRequest in amazonBookSearch use ../private/web.php (q.v., not in mercurial) for Aserver and Aassociates Started by updating from 40:c24ae74bf6d5, i.e. just before the bug on the main line
author Charlie Root
date Sat, 05 Jan 2019 18:00:10 -0500
parents 077b0a0a3e6d
children 385ddd7c4b55 a67bf725e87b
line wrap: on
line source

<?PHP
	include "../../private/db.php"; 

	include 'EpiCurl.php';
	include 'EpiOAuth.php';
	include 'EpiTwitter.php';
	include 'secret.php';

	$twitterObj = new EpiTwitter($consumer_key, $consumer_secret);

	$twitterObj->setToken($_GET['oauth_token']);
	$token = $twitterObj->getAccessToken();
	$twitterObj->setToken($token->oauth_token, $token->oauth_token_secret);

	// save to cookies
	setcookie('oauth_token', $token->oauth_token);
	setcookie('oauth_token_secret', $token->oauth_token_secret);

	$twitterInfo= $twitterObj->get_accountVerify_credentials();

	$User = "@" . $twitterInfo->screen_name;
	/*$link = mysqli_connect("localhost","root","");
	mysqli_select_db($link, "books");
	$User = "@" . "BWaaack";*/

	$sql1="SELECT FirstName, Surname, DisplayName, UserID from user WHERE Email ='$User'";
	//echo $sql1;
	$result1=mysqli_query($link,$sql1);

	// If successfully queried
	if($result1){
		$count=mysqli_num_rows($result1);
		if($count==0){
			//User doesn't already exist
			//set email to TwitterName
			//use defaults for other values	
			$add="CALL addNewUser('$User', 'twitter', '', '', 0, '$User', 0)";
			//echo $add;
			$result2 = mysqli_query($link, $add);
			
			//reset connection
			mysqli_close($link);
			include "../../private/db.php"; 
			
			$sql3="SELECT FirstName, Surname, DisplayName, UserID from user WHERE Email ='$User'";
			//echo $sql3;
			$resultFull=mysqli_query($link,$sql3);
		}
		else{
			$resultFull = $result1;
		}
		if($resultFull){	
			//User Exists
			$line=mysqli_fetch_array($resultFull, MYSQLI_ASSOC);
			$email = $line['Email'];
			$firstName=$line['FirstName'];
			$surname=$line['Surname'];
			$displayName=$line['DisplayName'];
			$id=$line['UserID'];
			
			if($displayName == "")
			{
				if($firstName == "")
					$displayName=$email;
				else
					$displayName = $firstName;
			}
			
			session_start();
			$_SESSION['displayName']=$displayName;
			$_SESSION['email']=$email;
			$_SESSION['surname']=$surname;
			$_SESSION['UserID']=$id;
			$_SESSION['receiveEmail']=$receiveEmail;
			$_SESSION['GRState']=$GRState;
			$_SESSION['Loc']=$LocID;
			echo session_id();
			echo ":::" . $displayName . ":::" . $surname . ":::" . $receiveEmail . ":::" . $GRState . ":::" . $LocID . ":::" . $email . ":::" . $id;
		}
	}
?>