d6e584b3 by Dan Rempel

Merge branch 'deploy' of git.gotenzing.com:tenzing/banners-with-skip into deploy

2 parents e3cb0cf1 aa312898
### old Files ###
/vendor/
......@@ -99,4 +99,5 @@ Desktop.ini
.svn/
/dummy.php
/wp-content/uploads/
\ No newline at end of file
/wp-content/uploads/
vendor/silex/silex
......
# ------------------------------------------------------------------------------
# | Cross-domain AJAX requests |
# ------------------------------------------------------------------------------
# Enable cross-origin AJAX requests.
# http://code.google.com/p/html5security/wiki/CrossOriginRequestSecurity
# http://enable-cors.org/
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "*"
</IfModule>
RewriteEngine On
# Prevents Flash files from caching
......
<?php
session_start();
if(!isset($_SESSION['google_data'])):header("Location:index.php");endif;
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Login with Google Account by CodexWorld</title>
<style type="text/css">
h1
{
font-family:Arial, Helvetica, sans-serif;
color:#999999;
}
.wrapper{width:600px; margin-left:auto;margin-right:auto;}
.welcome_txt{
margin: 20px;
background-color: #EBEBEB;
padding: 10px;
border: #D6D6D6 solid 1px;
-moz-border-radius:5px;
-webkit-border-radius:5px;
border-radius:5px;
}
.google_box{
margin: 20px;
background-color: #FFF0DD;
padding: 10px;
border: #F7CFCF solid 1px;
-moz-border-radius:5px;
-webkit-border-radius:5px;
border-radius:5px;
}
.google_box .image{ text-align:center;}
</style>
</head>
<body>
<div class="wrapper">
<h1>Google Profile Details </h1>
<?php
echo '<div class="welcome_txt">Welcome <b>'.$_SESSION['google_data']['given_name'].'</b></div>';
echo '<div class="google_box">';
echo '<p class="image"><img src="'.$_SESSION['google_data']['picture'].'" alt="" width="300" height="220"/></p>';
echo '<p><b>Google ID : </b>' . $_SESSION['google_data']['id'].'</p>';
echo '<p><b>Name : </b>' . $_SESSION['google_data']['name'].'</p>';
echo '<p><b>Email : </b>' . $_SESSION['google_data']['email'].'</p>';
echo '<p><b>Gender : </b>' . $_SESSION['google_data']['gender'].'</p>';
echo '<p><b>Locale : </b>' . $_SESSION['google_data']['locale'].'</p>';
echo '<p><b>Google+ Link : </b>' . $_SESSION['google_data']['link'].'</p>';
echo '<p><b>You are login with : </b>Google</p>';
echo '<p><b>Logout from <a href="logout.php?logout">Google</a></b></p>';
echo '</div>';
?>
</div>
</body>
<?php
if(!isset($_SESSION['google_data'])):header("Location:index.php");endif;
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Login with Google Account by CodexWorld</title>
<style type="text/css">
h1
{
font-family:Arial, Helvetica, sans-serif;
color:#999999;
}
.wrapper{width:600px; margin-left:auto;margin-right:auto;}
.welcome_txt{
margin: 20px;
background-color: #EBEBEB;
padding: 10px;
border: #D6D6D6 solid 1px;
-moz-border-radius:5px;
-webkit-border-radius:5px;
border-radius:5px;
}
.google_box{
margin: 20px;
background-color: #FFF0DD;
padding: 10px;
border: #F7CFCF solid 1px;
-moz-border-radius:5px;
-webkit-border-radius:5px;
border-radius:5px;
}
.google_box .image{ text-align:center;}
</style>
</head>
<body>
<div class="wrapper">
<h1>Google Profile Details </h1>
<?php
echo '<div class="welcome_txt">Welcome <b>'.$_SESSION['google_data']['given_name'].'</b></div>';
echo '<div class="google_box">';
echo '<p class="image"><img src="'.$_SESSION['google_data']['picture'].'" alt="" width="300" height="220"/></p>';
echo '<p><b>Google ID : </b>' . $_SESSION['google_data']['id'].'</p>';
echo '<p><b>Name : </b>' . $_SESSION['google_data']['name'].'</p>';
echo '<p><b>Email : </b>' . $_SESSION['google_data']['email'].'</p>';
echo '<p><b>Gender : </b>' . $_SESSION['google_data']['gender'].'</p>';
echo '<p><b>Locale : </b>' . $_SESSION['google_data']['locale'].'</p>';
echo '<p><b>Google+ Link : </b>' . $_SESSION['google_data']['link'].'</p>';
echo '<p><b>You are login with : </b>Google</p>';
echo '<p><b>Logout from <a href="logout.php?logout">Google</a></b></p>';
echo '</div>';
?>
</div>
</body>
</html>
\ No newline at end of file
......
{
"name": "googleplus/quickstart",
"description": "This quick-start app is built in PHP and lets you get started with the Google+ platform in a few minutes.",
"license": "Apache-2.0",
"repositories": [
{
"type": "package",
"package": {
"name": "google/apiclient",
"version": "1.1.7",
"source": {
"url": "https://github.com/google/google-api-php-client.git",
"type": "git",
"reference": "v1-master"
},
"autoload": {
"classmap": [
"src/"
]
}
}
}
],
"require": {
"silex/silex": "1.0.*@dev",
"twig/twig": ">=1.8,<2.0-dev",
"google/apiclient": "1.1.*",
"guzzlehttp/guzzle": "5.2.*"
}
}
<?php
//session_start();
include_once("src/Google_Client.php");
include_once("src/contrib/Google_Oauth2Service.php");
######### edit details ##########
$clientId = '326088686201-1llld5s7s3uhb2shl4g2g9djkvq584pc.apps.googleusercontent.com'; //Google CLIENT ID
$clientSecret = 'F4Fa8MdTT17f4voG4lRaOCuc'; //Google CLIENT SECRET
$redirectUrl = 'http://banners.gotenzing.com/login.php'; //return url (url to script)
$homeUrl = 'http://banners.gotenzing.com'; //return to home
##################################
$gClient = new Google_Client();
$gClient->setApplicationName('banners.gotenzing.com');
$gClient->setClientId($clientId);
$gClient->setClientSecret($clientSecret);
$gClient->setRedirectUri($redirectUrl);
$google_oauthV2 = new Google_Oauth2Service($gClient);
?>
\ No newline at end of file
<?php
class Users {
public $tableName = 'users';
function __construct(){
//database configuration
$dbServer = 'localhost'; //Define database server host
$dbUsername = 'banners'; //Define database username
$dbPassword = 'root'; //Define database password
$dbName = 'banners'; //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,$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."', 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."', 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;
}
}
?>
\ No newline at end of file
<?php
// if (!isset($_SESSION) && !isset($_SESSION['username'])) {
// return;
// }
<?php
session_start();
if (!isset($_SESSION) && !isset($_SESSION['token'])) {
?>
<script>
$(document).ready(function() {
$('authOps').empty();
});
</script>
<?php
return;
}
$dockets = Array();
$dockets_obj = json_decode($_SESSION['lookup']);
foreach ($dockets_obj as $docket => $key) {
......@@ -68,7 +78,7 @@
<dd>http://<?php echo $_GET['d'];?>/<span><?php echo $id;?></span></dd>
</dl>
<?php /*?> <button style="margin-top:20px; width:100px;" id="disconnect" >Disconnect</button><?php */?>
<script type = 'text/javascript'>
$('#client_menu').on('change',function(){
......
<?php
session_start();
@ini_set("session.use_trans_sid","0");
@ini_set('session.gc_probability', 1);
//let it work please again
$dockets = Array();
$valid = 'home.html';
......
<?php
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
......@@ -33,37 +28,38 @@
float: left;
margin: 15px;
height: 65px;
}
ul.TzMenu {
list-style: none;
padding-left: 0;
}
#TzLogo {
float: right;
float: right;
width: 259px;
position: absolute;
right: 0;
top: -5px;
}
#submit { margin-left: 6px; }
#customBtn{
margin-top:10px;
}
dd { margin-left: 0; }
#customBtn:hover {
box-shadow: 0px 0px 0px #888888 !important;
border-radius: 0px !important;
cursor: hand;
}
</style>
<script type="text/javascript" src="addEvent.js"></script>
</head>
<body>
<?php
if (isset($_SESSION['username'])) {
include('includes/loggedin.php');
} else {
include('includes/auth.php');
}
?>
<div style="width:80%;"><?php
include('signinView.php');
?>
</div>
<div id="TzLogo">
<img src="tenzing.gif" width="259" height="75" alt="Tenzing" />
</div>
......
<?php
/*
* Sample application for Google+ client to server authentication.
* Remember to fill in the OAuth 2.0 client id and client secret,
* which can be obtained from the Google Developer Console at
* https://code.google.com/apis/console
*
* Copyright 2013 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* Note (Gerwin Sturm):
* Include path is still necessary despite autoloading because of the require_once in the libary
* Client library should be fixed to have correct relative paths
* e.g. require_once '../Google/Model.php'; instead of require_once 'Google/Model.php';
*/
set_include_path(get_include_path() . PATH_SEPARATOR . __DIR__ .'/vendor/google/apiclient/src');
require_once __DIR__.'/vendor/autoload.php';
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
/**
* Simple server to demonstrate how to use Google+ Sign-In and make a request
* via your own server.
*
* @author silvano@google.com (Silvano Luciani)
*/
/**
* Replace this with the client ID you got from the Google APIs console.
*/
const CLIENT_ID = '326088686201-1llld5s7s3uhb2shl4g2g9djkvq584pc.apps.googleusercontent.com';
/**
* Replace this with the client secret you got from the Google APIs console.
*/
const CLIENT_SECRET = 'F4Fa8MdTT17f4voG4lRaOCuc';
/**
* Optionally replace this with your application's name.
*/
const APPLICATION_NAME = "banners.gotenzing.com";
$client = new Google_Client();
$client->setAccessType('online'); // default: offline
$client->setApplicationName(APPLICATION_NAME);
$client->setClientId(CLIENT_ID);
$client->setClientSecret(CLIENT_SECRET);
$client->setDeveloperKey("AIzaSyD_VREr-We898pVftz2T3c9EU7kKkylSPs");
$client->setRedirectUri('postmessage');
$plus = new Google_Service_Plus($client);
$app = new Silex\Application();
$app['debug'] = true;
$app->register(new Silex\Provider\TwigServiceProvider(), array(
'twig.path' => __DIR__,
));
$app->register(new Silex\Provider\SessionServiceProvider());
// Initialize a session for the current user, and render index.html.
$app->get('/', function () use ($app) {
$state = "f4325120986c13bf5f55fbb8feab9105";
$app['session']->set('state', $state);
return $app['twig']->render('signin.php', array(
'CLIENT_ID' => CLIENT_ID,
'STATE' => $state,
'APPLICATION_NAME' => APPLICATION_NAME
));
});
// Upgrade given auth code to token, and store it in the session.
// POST body of request should be the authorization code.
// Example URI: /connect?state=...&gplus_id=...
$app->post('/connect', function (Request $request) use ($app, $client) {
$token = $app['session']->get('token');
if (empty($token)) {
// Ensure that this is no request forgery going on, and that the user
// Normally the state would be a one-time use token, however in our
// simple case, we want a user to be able to connect and disconnect
// without reloading the page. Thus, for demonstration, we don't
// implement this best practice.
//$app['session']->set('state', '');
$code = $request->getContent();
// Exchange the OAuth 2.0 authorization code for user credentials.
$client->authenticate($code);
$token = json_decode($client->getAccessToken());
$_SESSION['token']= $token;
// You can read the Google user ID in the ID token.
// "sub" represents the ID token subscriber which in our case
// is the user ID. This sample does not use the user ID.
$attributes = $client->verifyIdToken($token->id_token, CLIENT_ID)
->getAttributes();
$gplus_id = $attributes["payload"]["sub"];
// Store the token in the session for later use.
$app['session']->set('token', json_encode($token));
$response = 'Successfully connected with token: ' . print_r($token, true);
} else {
$response = 'Already connected';
}
return new Response($response, 200);
});
// Get list of activities visible to this app.
$app->get('/activities', function () use ($app, $client, $plus) {
$token = $app['session']->get('token');
//if (empty($token)) {
//return new Response('Unauthorized request', 401);
//}
$client->setAccessToken($token);
$activities = $plus->activities->listActivities('me', 'public', array());
/*
* Note (Gerwin Sturm):
* $app->json($activities) ignores the $activities->items not returning this array
* Probably needs to be fixed in the Client Library
* Using ->toSimpleObject for now to get a JSON-convertible object
*/
return $app->json($activities->toSimpleObject());
});
// Revoke current user's token and reset their session.
$app->post('/disconnect', function () use ($app, $client) {
//error_log(print_r($app, true));
$token = json_decode($app['session']->get('token'))->access_token;
$client->revokeToken($token);
// Remove the credentials from the user's session.
$app['session']->set('token', '');
unset($app);
unset($client);
unset($_SESSION);
session_start();
session_destroy();
session_unset();
session_write_close();
setcookie(session_name(),'',0,'/');
session_regenerate_id(true);
error_log('destroy');
return new Response('Successfully disconnected', 200);
});
$app->run();
<!DOCTYPE HTML>
<script type="text/javascript">
var auth2 = auth2 || {};
(function() {
var po = document.createElement('script');
po.type = 'text/javascript'; po.async = true;
po.src = 'https://plus.google.com/js/client:plusone.js?onload=startApp';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(po, s);
})();
var CLIENT_ID = '326088686201-1llld5s7s3uhb2shl4g2g9djkvq584pc.apps.googleusercontent.com';
/**
* Replace this with the client secret you got from the Google APIs console.
*/
var CLIENT_SECRET = 'F4Fa8MdTT17f4voG4lRaOCuc';
/**
* Optionally replace this with your application's name.
*/
var APPLICATION_NAME = "banners.gotenzing.com";
var STATE = "f4325120986c13bf5f55fbb8feab9105";
</script>
<!-- JavaScript specific to this application that is not related to API
calls -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js" ></script>
<style>
#customBtn {
width: 155px;
}
#customBtn:hover {
box-shadow: 2px 2px 3px #888888;
border-radius: 5px;
cursor: hand;
}
</style>
<div id="gConnect" >
<img id="customBtn" src="./signin_button.png" onClick="signInClick()"
alt="Sign in with Google+" />
</div>
<div id="authOps" style="display:none">
<?php
include('includes/loggedin.php');
?>
</div>
<script type="text/javascript">
var helper = (function() {
var authResult = undefined;
return {
/**
* Hides the sign-in button and connects the server-side app after
* the user successfully signs in.
*
* @param {Object} authResult An Object which contains the access token and
* other authentication information.
*/
onSignInCallback: function(authResult) {
$('#authResult').html('Auth Result:<br/>');
for (var field in authResult) {
$('#authResult').append(' ' + field + ': ' + authResult[field] + '<br/>');
}
if (authResult['access_token']) {
// The user is signed in
this.authResult = authResult;
// After we load the Google+ API, render the profile data from Google+.
gapi.client.load('plus','v1',this.renderProfile);
// After we load the profile, retrieve the list of activities visible
// to this app, server-side.
helper.activities();
} else if (authResult['error']) {
// There was an error, which means the user is not signed in.
// As an example, you can troubleshoot by writing to the console:
console.log('There was an error: ' + authResult['error']);
$('#authResult').append('Logged out');
$('#authOps').hide('slow');
$('#gConnect').show();
}
console.log('authResult', authResult);
},
/**
* Retrieves and renders the authenticated user's Google+ profile.
*/
renderProfile: function() {
var req = gapi.client.plus.people.get( {'userId' : 'me'} );
var req = req.execute(handleEmailResponse);
var request = gapi.client.plus.people.get( {'userId' : 'me'} );
request.execute(function(profile) {
$('#profile').empty();
if (profile.error) {
$('#profile').append(profile.error);
return;
}
// console.log(people);
console.log('test');
$('#profile').append(
$('<p><img src=\"' + profile.image.url + '\"></p>'));
$('#profile').append(
$('<p>Hello ' + profile.displayName + '!<br />Tagline: ' +
profile.tagline + '<br />About: ' + profile.aboutMe + '</p>'));
if (profile.cover && profile.coverPhoto) {
$('#profile').append(
$('<p><img src=\"' + profile.cover.coverPhoto.url + '\"></p>'));
}
});
$('#authOps').show('slow');
$('#gConnect').hide();
},
/**
* Calls the server endpoint to disconnect the app for the user.
*/
disconnectServer: function() {
// Revoke the server tokens
$.ajax({
type: 'POST',
url: $(location).attr('origin') + '/signin.php/disconnect',
async: false,
success: function(result) {
console.log('revoke response: ' + result);
$('#authOps').hide();
$('#profile').empty();
$('#visiblePeople').empty();
$('#authResult').empty();
$('#gConnect').show();
},
error: function(e) {
console.log(e);
}
});
},
/**
* Calls the server endpoint to connect the app for the user. The client
* sends the one-time authorization code to the server and the server
* exchanges the code for its own tokens to use for offline API access.
* For more information, see:
* https://developers.google.com/+/web/signin/server-side-flow
*/
connectServer: function(code) {
console.log(code);
$.ajax({
type: 'POST',
url: $(location).attr('origin') + '/signin.php/connect?state='+STATE,
contentType: 'application/octet-stream; charset=utf-8',
success: function(result) {
console.log(result);
helper.activities();
onSignInCallback(auth2.currentUser.get().getAuthResponse());
},
error: function(result){
console.log(result);
},
processData: false,
data: code
});
},
/**
* Calls the server endpoint to get the list of activities visible to this
* app.
* @param success Callback called on success.
* @param failure Callback called on error.
*/
activities: function(success, failure) {
success = success || function(result) { helper.appendActivity(result); };
$.ajax({
type: 'GET',
url: $(location).attr('origin') + '/signin.php/activities',
contentType: 'application/octet-stream; charset=utf-8',
success: success,
error: failure,
processData: false
});
},
/**
* Displays visible People retrieved from server.
*
* @param {Object} activities A list of Google+ activity resources.
*/
appendActivity: function(activities) {
$('#activities').empty();
},
};
})();
/**
* Perform jQuery initialization and check to ensure that you updated your
* client ID.
*/
$(document).ready(function() {
$('#disconnect').click(helper.disconnectServer);
if ($('[data-clientid="YOUR_CLIENT_ID"]').length > 0) {
alert('This sample requires your OAuth credentials (client ID) ' +
'from the Google APIs console:\n' +
' https://code.google.com/apis/console/#:access\n\n' +
'Find and replace YOUR_CLIENT_ID with your client ID and ' +
'YOUR_CLIENT_SECRET with your client secret in the project sources.'
);
}
});
/**
* Called after the Google client library has loaded.
*/
function startApp() {
gapi.load('auth2', function(){
// Retrieve the singleton for the GoogleAuth library and setup the client.
gapi.auth2.init({
client_id: CLIENT_ID,
cookiepolicy: 'single_host_origin',
fetch_basic_profile: false,
scope: 'https://www.googleapis.com/auth/userinfo.email'
}).then(function (){
console.log('init');
auth2 = gapi.auth2.getAuthInstance();
auth2.then(function() {
var isAuthedCallback = function () {
onSignInCallback(auth2.currentUser.get().getAuthResponse())
}
helper.activities(isAuthedCallback);
});
});
});
}
/**
* Either signs the user in or authorizes the back-end.
*/
function signInClick() {
var signIn = function(result) {
auth2.signIn().then(
function(googleUser) {
onSignInCallback(googleUser.getAuthResponse());
}, function(error) {
alert(JSON.stringify(error, undefined, 2));
});
};
var reauthorize = function() {
auth2.grantOfflineAccess().then(
function(result){
helper.connectServer(result.code);
});
};
helper.activities(signIn, reauthorize);
}
/**
* Calls the helper method that handles the authentication flow.
*
* @param {Object} authResult An Object which contains the access token and
* other authentication information.
*/
function handleEmailResponse(resp) {
var primaryEmail;
for (var i=0; i < resp.emails.length; i++) {
if (resp.emails[i].type === 'account') primaryEmail = resp.emails[i].value;
}
var domain = primaryEmail.substring(primaryEmail.lastIndexOf("@") +1);
if(domain != 'gotenzing.com'){
$(document).ready(function() {
$.ajax({
type: 'POST',
url: $(location).attr('origin') + '/signin.php/disconnect',
async: false,
success: function(result) {
console.log('revoke response: ' + result);
$('#authOps').hide();
$('#profile').empty();
$('#visiblePeople').empty();
$('#authResult').empty();
$('#gConnect').show();
$('authOps').empty();
},
error: function(e) {
console.log(e);
}
});
});
}
console.log( domain);
}
function onSignInCallback(authResult) {
helper.onSignInCallback(authResult);
}
</script>