Merge branch 'deploy' of git.gotenzing.com:tenzing/banners-with-skip into deploy
Showing
13 changed files
with
626 additions
and
141 deletions
| 1 | ### old Files ### | 1 | ### old Files ### |
| 2 | 2 | ||
| 3 | 3 | /vendor/ | |
| 4 | 4 | ||
| 5 | 5 | ||
| 6 | 6 | ||
| ... | @@ -99,4 +99,5 @@ Desktop.ini | ... | @@ -99,4 +99,5 @@ Desktop.ini |
| 99 | .svn/ | 99 | .svn/ |
| 100 | 100 | ||
| 101 | /dummy.php | 101 | /dummy.php |
| 102 | /wp-content/uploads/ | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 102 | /wp-content/uploads/ | ||
| 103 | vendor/silex/silex | ... | ... |
| 1 | # ------------------------------------------------------------------------------ | ||
| 2 | # | Cross-domain AJAX requests | | ||
| 3 | # ------------------------------------------------------------------------------ | ||
| 4 | |||
| 5 | # Enable cross-origin AJAX requests. | ||
| 6 | # http://code.google.com/p/html5security/wiki/CrossOriginRequestSecurity | ||
| 7 | # http://enable-cors.org/ | ||
| 8 | |||
| 9 | <IfModule mod_headers.c> | ||
| 10 | Header set Access-Control-Allow-Origin "*" | ||
| 11 | </IfModule> | ||
| 12 | |||
| 13 | |||
| 1 | RewriteEngine On | 14 | RewriteEngine On |
| 2 | 15 | ||
| 3 | # Prevents Flash files from caching | 16 | # Prevents Flash files from caching | ... | ... |
| 1 | <?php | 1 | <?php |
| 2 | session_start(); | 2 | |
| 3 | if(!isset($_SESSION['google_data'])):header("Location:index.php");endif; | 3 | if(!isset($_SESSION['google_data'])):header("Location:index.php");endif; |
| 4 | ?> | 4 | ?> |
| 5 | <html> | 5 | <html> |
| 6 | <head> | 6 | <head> |
| 7 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | 7 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
| 8 | <title>Login with Google Account by CodexWorld</title> | 8 | <title>Login with Google Account by CodexWorld</title> |
| 9 | <style type="text/css"> | 9 | <style type="text/css"> |
| 10 | h1 | 10 | h1 |
| 11 | { | 11 | { |
| 12 | font-family:Arial, Helvetica, sans-serif; | 12 | font-family:Arial, Helvetica, sans-serif; |
| 13 | color:#999999; | 13 | color:#999999; |
| 14 | } | 14 | } |
| 15 | .wrapper{width:600px; margin-left:auto;margin-right:auto;} | 15 | .wrapper{width:600px; margin-left:auto;margin-right:auto;} |
| 16 | .welcome_txt{ | 16 | .welcome_txt{ |
| 17 | margin: 20px; | 17 | margin: 20px; |
| 18 | background-color: #EBEBEB; | 18 | background-color: #EBEBEB; |
| 19 | padding: 10px; | 19 | padding: 10px; |
| 20 | border: #D6D6D6 solid 1px; | 20 | border: #D6D6D6 solid 1px; |
| 21 | -moz-border-radius:5px; | 21 | -moz-border-radius:5px; |
| 22 | -webkit-border-radius:5px; | 22 | -webkit-border-radius:5px; |
| 23 | border-radius:5px; | 23 | border-radius:5px; |
| 24 | } | 24 | } |
| 25 | .google_box{ | 25 | .google_box{ |
| 26 | margin: 20px; | 26 | margin: 20px; |
| 27 | background-color: #FFF0DD; | 27 | background-color: #FFF0DD; |
| 28 | padding: 10px; | 28 | padding: 10px; |
| 29 | border: #F7CFCF solid 1px; | 29 | border: #F7CFCF solid 1px; |
| 30 | -moz-border-radius:5px; | 30 | -moz-border-radius:5px; |
| 31 | -webkit-border-radius:5px; | 31 | -webkit-border-radius:5px; |
| 32 | border-radius:5px; | 32 | border-radius:5px; |
| 33 | } | 33 | } |
| 34 | .google_box .image{ text-align:center;} | 34 | .google_box .image{ text-align:center;} |
| 35 | </style> | 35 | </style> |
| 36 | </head> | 36 | </head> |
| 37 | <body> | 37 | <body> |
| 38 | <div class="wrapper"> | 38 | <div class="wrapper"> |
| 39 | <h1>Google Profile Details </h1> | 39 | <h1>Google Profile Details </h1> |
| 40 | <?php | 40 | <?php |
| 41 | echo '<div class="welcome_txt">Welcome <b>'.$_SESSION['google_data']['given_name'].'</b></div>'; | 41 | echo '<div class="welcome_txt">Welcome <b>'.$_SESSION['google_data']['given_name'].'</b></div>'; |
| 42 | echo '<div class="google_box">'; | 42 | echo '<div class="google_box">'; |
| 43 | echo '<p class="image"><img src="'.$_SESSION['google_data']['picture'].'" alt="" width="300" height="220"/></p>'; | 43 | echo '<p class="image"><img src="'.$_SESSION['google_data']['picture'].'" alt="" width="300" height="220"/></p>'; |
| 44 | echo '<p><b>Google ID : </b>' . $_SESSION['google_data']['id'].'</p>'; | 44 | echo '<p><b>Google ID : </b>' . $_SESSION['google_data']['id'].'</p>'; |
| 45 | echo '<p><b>Name : </b>' . $_SESSION['google_data']['name'].'</p>'; | 45 | echo '<p><b>Name : </b>' . $_SESSION['google_data']['name'].'</p>'; |
| 46 | echo '<p><b>Email : </b>' . $_SESSION['google_data']['email'].'</p>'; | 46 | echo '<p><b>Email : </b>' . $_SESSION['google_data']['email'].'</p>'; |
| 47 | echo '<p><b>Gender : </b>' . $_SESSION['google_data']['gender'].'</p>'; | 47 | echo '<p><b>Gender : </b>' . $_SESSION['google_data']['gender'].'</p>'; |
| 48 | echo '<p><b>Locale : </b>' . $_SESSION['google_data']['locale'].'</p>'; | 48 | echo '<p><b>Locale : </b>' . $_SESSION['google_data']['locale'].'</p>'; |
| 49 | echo '<p><b>Google+ Link : </b>' . $_SESSION['google_data']['link'].'</p>'; | 49 | echo '<p><b>Google+ Link : </b>' . $_SESSION['google_data']['link'].'</p>'; |
| 50 | echo '<p><b>You are login with : </b>Google</p>'; | 50 | echo '<p><b>You are login with : </b>Google</p>'; |
| 51 | echo '<p><b>Logout from <a href="logout.php?logout">Google</a></b></p>'; | 51 | echo '<p><b>Logout from <a href="logout.php?logout">Google</a></b></p>'; |
| 52 | echo '</div>'; | 52 | echo '</div>'; |
| 53 | ?> | 53 | ?> |
| 54 | </div> | 54 | </div> |
| 55 | </body> | 55 | </body> |
| 56 | </html> | 56 | </html> |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
composer.json
0 → 100644
| 1 | { | ||
| 2 | "name": "googleplus/quickstart", | ||
| 3 | "description": "This quick-start app is built in PHP and lets you get started with the Google+ platform in a few minutes.", | ||
| 4 | "license": "Apache-2.0", | ||
| 5 | "repositories": [ | ||
| 6 | { | ||
| 7 | "type": "package", | ||
| 8 | "package": { | ||
| 9 | "name": "google/apiclient", | ||
| 10 | "version": "1.1.7", | ||
| 11 | "source": { | ||
| 12 | "url": "https://github.com/google/google-api-php-client.git", | ||
| 13 | "type": "git", | ||
| 14 | "reference": "v1-master" | ||
| 15 | }, | ||
| 16 | "autoload": { | ||
| 17 | "classmap": [ | ||
| 18 | "src/" | ||
| 19 | ] | ||
| 20 | } | ||
| 21 | } | ||
| 22 | } | ||
| 23 | ], | ||
| 24 | "require": { | ||
| 25 | "silex/silex": "1.0.*@dev", | ||
| 26 | "twig/twig": ">=1.8,<2.0-dev", | ||
| 27 | "google/apiclient": "1.1.*", | ||
| 28 | "guzzlehttp/guzzle": "5.2.*" | ||
| 29 | } | ||
| 30 | } |
composer.lock
0 → 100644
This diff is collapsed.
Click to expand it.
config.php
deleted
100755 → 0
| 1 | <?php | ||
| 2 | //session_start(); | ||
| 3 | include_once("src/Google_Client.php"); | ||
| 4 | include_once("src/contrib/Google_Oauth2Service.php"); | ||
| 5 | ######### edit details ########## | ||
| 6 | $clientId = '326088686201-1llld5s7s3uhb2shl4g2g9djkvq584pc.apps.googleusercontent.com'; //Google CLIENT ID | ||
| 7 | $clientSecret = 'F4Fa8MdTT17f4voG4lRaOCuc'; //Google CLIENT SECRET | ||
| 8 | $redirectUrl = 'http://banners.gotenzing.com/login.php'; //return url (url to script) | ||
| 9 | $homeUrl = 'http://banners.gotenzing.com'; //return to home | ||
| 10 | |||
| 11 | ################################## | ||
| 12 | |||
| 13 | $gClient = new Google_Client(); | ||
| 14 | $gClient->setApplicationName('banners.gotenzing.com'); | ||
| 15 | $gClient->setClientId($clientId); | ||
| 16 | $gClient->setClientSecret($clientSecret); | ||
| 17 | $gClient->setRedirectUri($redirectUrl); | ||
| 18 | |||
| 19 | $google_oauthV2 = new Google_Oauth2Service($gClient); | ||
| 20 | ?> | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
includes/functions.php
deleted
100755 → 0
| 1 | <?php | ||
| 2 | class Users { | ||
| 3 | public $tableName = 'users'; | ||
| 4 | |||
| 5 | function __construct(){ | ||
| 6 | //database configuration | ||
| 7 | $dbServer = 'localhost'; //Define database server host | ||
| 8 | $dbUsername = 'banners'; //Define database username | ||
| 9 | $dbPassword = 'root'; //Define database password | ||
| 10 | $dbName = 'banners'; //Define database name | ||
| 11 | |||
| 12 | //connect databse | ||
| 13 | |||
| 14 | $con = mysqli_connect($dbServer,$dbUsername,$dbPassword,$dbName); | ||
| 15 | if(mysqli_connect_errno()){ | ||
| 16 | die("Failed to connect with MySQL: ".mysqli_connect_error()); | ||
| 17 | }else{ | ||
| 18 | $this->connect = $con; | ||
| 19 | } | ||
| 20 | } | ||
| 21 | |||
| 22 | function checkUser($oauth_provider,$oauth_uid,$fname,$lname,$email,$gender,$locale,$link,$picture){ | ||
| 23 | $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)); | ||
| 24 | if(mysqli_num_rows($prevQuery) > 0){ | ||
| 25 | $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)); | ||
| 26 | }else{ | ||
| 27 | $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)); | ||
| 28 | } | ||
| 29 | |||
| 30 | $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)); | ||
| 31 | $result = mysqli_fetch_array($query); | ||
| 32 | return $result; | ||
| 33 | } | ||
| 34 | } | ||
| 35 | ?> | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | <?php | 1 | <?php |
| 2 | // if (!isset($_SESSION) && !isset($_SESSION['username'])) { | 2 | session_start(); |
| 3 | // return; | 3 | if (!isset($_SESSION) && !isset($_SESSION['token'])) { |
| 4 | // } | 4 | ?> |
| 5 | 5 | <script> | |
| 6 | $(document).ready(function() { | ||
| 7 | |||
| 8 | $('authOps').empty(); | ||
| 9 | |||
| 10 | }); | ||
| 11 | </script> | ||
| 12 | <?php | ||
| 13 | return; | ||
| 14 | } | ||
| 6 | 15 | ||
| 16 | |||
| 7 | $dockets = Array(); | 17 | $dockets = Array(); |
| 8 | $dockets_obj = json_decode($_SESSION['lookup']); | 18 | $dockets_obj = json_decode($_SESSION['lookup']); |
| 9 | foreach ($dockets_obj as $docket => $key) { | 19 | foreach ($dockets_obj as $docket => $key) { |
| ... | @@ -68,7 +78,7 @@ | ... | @@ -68,7 +78,7 @@ |
| 68 | <dd>http://<?php echo $_GET['d'];?>/<span><?php echo $id;?></span></dd> | 78 | <dd>http://<?php echo $_GET['d'];?>/<span><?php echo $id;?></span></dd> |
| 69 | </dl> | 79 | </dl> |
| 70 | 80 | ||
| 71 | 81 | <?php /*?> <button style="margin-top:20px; width:100px;" id="disconnect" >Disconnect</button><?php */?> | |
| 72 | <script type = 'text/javascript'> | 82 | <script type = 'text/javascript'> |
| 73 | 83 | ||
| 74 | $('#client_menu').on('change',function(){ | 84 | $('#client_menu').on('change',function(){ | ... | ... |
| 1 | <?php | ||
| 2 | session_start(); | ||
| 3 | |||
| 4 | ?> | ||
| 5 | |||
| 6 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
| 7 | <html xmlns="http://www.w3.org/1999/xhtml"> | 2 | <html xmlns="http://www.w3.org/1999/xhtml"> |
| 8 | <head> | 3 | <head> |
| ... | @@ -33,37 +28,38 @@ | ... | @@ -33,37 +28,38 @@ |
| 33 | float: left; | 28 | float: left; |
| 34 | margin: 15px; | 29 | margin: 15px; |
| 35 | height: 65px; | 30 | height: 65px; |
| 31 | |||
| 36 | } | 32 | } |
| 37 | ul.TzMenu { | 33 | ul.TzMenu { |
| 38 | list-style: none; | 34 | list-style: none; |
| 39 | padding-left: 0; | 35 | padding-left: 0; |
| 40 | } | 36 | } |
| 41 | #TzLogo { | 37 | #TzLogo { |
| 42 | float: right; | 38 | float: right; |
| 43 | width: 259px; | 39 | width: 259px; |
| 40 | position: absolute; | ||
| 41 | right: 0; | ||
| 42 | top: -5px; | ||
| 43 | |||
| 44 | } | 44 | } |
| 45 | #submit { margin-left: 6px; } | 45 | #submit { margin-left: 6px; } |
| 46 | 46 | #customBtn{ | |
| 47 | margin-top:10px; | ||
| 48 | } | ||
| 47 | dd { margin-left: 0; } | 49 | dd { margin-left: 0; } |
| 50 | #customBtn:hover { | ||
| 51 | box-shadow: 0px 0px 0px #888888 !important; | ||
| 52 | border-radius: 0px !important; | ||
| 53 | cursor: hand; | ||
| 54 | } | ||
| 48 | </style> | 55 | </style> |
| 49 | |||
| 50 | <script type="text/javascript" src="addEvent.js"></script> | 56 | <script type="text/javascript" src="addEvent.js"></script> |
| 51 | |||
| 52 | </head> | 57 | </head> |
| 53 | |||
| 54 | <body> | 58 | <body> |
| 55 | 59 | <div style="width:80%;"><?php | |
| 56 | <?php | 60 | include('signinView.php'); |
| 57 | 61 | ?> | |
| 58 | 62 | </div> | |
| 59 | |||
| 60 | if (isset($_SESSION['username'])) { | ||
| 61 | include('includes/loggedin.php'); | ||
| 62 | } else { | ||
| 63 | include('includes/auth.php'); | ||
| 64 | } | ||
| 65 | ?> | ||
| 66 | |||
| 67 | <div id="TzLogo"> | 63 | <div id="TzLogo"> |
| 68 | <img src="tenzing.gif" width="259" height="75" alt="Tenzing" /> | 64 | <img src="tenzing.gif" width="259" height="75" alt="Tenzing" /> |
| 69 | </div> | 65 | </div> | ... | ... |
signin.php
0 → 100755
| 1 | <?php | ||
| 2 | /* | ||
| 3 | * Sample application for Google+ client to server authentication. | ||
| 4 | * Remember to fill in the OAuth 2.0 client id and client secret, | ||
| 5 | * which can be obtained from the Google Developer Console at | ||
| 6 | * https://code.google.com/apis/console | ||
| 7 | * | ||
| 8 | * Copyright 2013 Google Inc. | ||
| 9 | * | ||
| 10 | * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 11 | * you may not use this file except in compliance with the License. | ||
| 12 | * You may obtain a copy of the License at | ||
| 13 | * | ||
| 14 | * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 15 | * | ||
| 16 | * Unless required by applicable law or agreed to in writing, software | ||
| 17 | * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 19 | * See the License for the specific language governing permissions and | ||
| 20 | * limitations under the License. | ||
| 21 | */ | ||
| 22 | |||
| 23 | /* | ||
| 24 | * Note (Gerwin Sturm): | ||
| 25 | * Include path is still necessary despite autoloading because of the require_once in the libary | ||
| 26 | * Client library should be fixed to have correct relative paths | ||
| 27 | * e.g. require_once '../Google/Model.php'; instead of require_once 'Google/Model.php'; | ||
| 28 | */ | ||
| 29 | set_include_path(get_include_path() . PATH_SEPARATOR . __DIR__ .'/vendor/google/apiclient/src'); | ||
| 30 | |||
| 31 | require_once __DIR__.'/vendor/autoload.php'; | ||
| 32 | |||
| 33 | use Symfony\Component\HttpFoundation\Request; | ||
| 34 | use Symfony\Component\HttpFoundation\Response; | ||
| 35 | |||
| 36 | /** | ||
| 37 | * Simple server to demonstrate how to use Google+ Sign-In and make a request | ||
| 38 | * via your own server. | ||
| 39 | * | ||
| 40 | * @author silvano@google.com (Silvano Luciani) | ||
| 41 | */ | ||
| 42 | |||
| 43 | /** | ||
| 44 | * Replace this with the client ID you got from the Google APIs console. | ||
| 45 | */ | ||
| 46 | const CLIENT_ID = '326088686201-1llld5s7s3uhb2shl4g2g9djkvq584pc.apps.googleusercontent.com'; | ||
| 47 | |||
| 48 | /** | ||
| 49 | * Replace this with the client secret you got from the Google APIs console. | ||
| 50 | */ | ||
| 51 | const CLIENT_SECRET = 'F4Fa8MdTT17f4voG4lRaOCuc'; | ||
| 52 | |||
| 53 | /** | ||
| 54 | * Optionally replace this with your application's name. | ||
| 55 | */ | ||
| 56 | const APPLICATION_NAME = "banners.gotenzing.com"; | ||
| 57 | |||
| 58 | $client = new Google_Client(); | ||
| 59 | $client->setAccessType('online'); // default: offline | ||
| 60 | $client->setApplicationName(APPLICATION_NAME); | ||
| 61 | $client->setClientId(CLIENT_ID); | ||
| 62 | $client->setClientSecret(CLIENT_SECRET); | ||
| 63 | $client->setDeveloperKey("AIzaSyD_VREr-We898pVftz2T3c9EU7kKkylSPs"); | ||
| 64 | $client->setRedirectUri('postmessage'); | ||
| 65 | |||
| 66 | |||
| 67 | |||
| 68 | $plus = new Google_Service_Plus($client); | ||
| 69 | |||
| 70 | $app = new Silex\Application(); | ||
| 71 | $app['debug'] = true; | ||
| 72 | |||
| 73 | $app->register(new Silex\Provider\TwigServiceProvider(), array( | ||
| 74 | 'twig.path' => __DIR__, | ||
| 75 | )); | ||
| 76 | $app->register(new Silex\Provider\SessionServiceProvider()); | ||
| 77 | |||
| 78 | // Initialize a session for the current user, and render index.html. | ||
| 79 | $app->get('/', function () use ($app) { | ||
| 80 | $state = "f4325120986c13bf5f55fbb8feab9105"; | ||
| 81 | $app['session']->set('state', $state); | ||
| 82 | return $app['twig']->render('signin.php', array( | ||
| 83 | 'CLIENT_ID' => CLIENT_ID, | ||
| 84 | 'STATE' => $state, | ||
| 85 | 'APPLICATION_NAME' => APPLICATION_NAME | ||
| 86 | )); | ||
| 87 | }); | ||
| 88 | |||
| 89 | // Upgrade given auth code to token, and store it in the session. | ||
| 90 | // POST body of request should be the authorization code. | ||
| 91 | // Example URI: /connect?state=...&gplus_id=... | ||
| 92 | $app->post('/connect', function (Request $request) use ($app, $client) { | ||
| 93 | $token = $app['session']->get('token'); | ||
| 94 | |||
| 95 | if (empty($token)) { | ||
| 96 | // Ensure that this is no request forgery going on, and that the user | ||
| 97 | |||
| 98 | |||
| 99 | // Normally the state would be a one-time use token, however in our | ||
| 100 | // simple case, we want a user to be able to connect and disconnect | ||
| 101 | // without reloading the page. Thus, for demonstration, we don't | ||
| 102 | // implement this best practice. | ||
| 103 | //$app['session']->set('state', ''); | ||
| 104 | |||
| 105 | $code = $request->getContent(); | ||
| 106 | // Exchange the OAuth 2.0 authorization code for user credentials. | ||
| 107 | $client->authenticate($code); | ||
| 108 | $token = json_decode($client->getAccessToken()); | ||
| 109 | |||
| 110 | |||
| 111 | $_SESSION['token']= $token; | ||
| 112 | |||
| 113 | |||
| 114 | // You can read the Google user ID in the ID token. | ||
| 115 | // "sub" represents the ID token subscriber which in our case | ||
| 116 | // is the user ID. This sample does not use the user ID. | ||
| 117 | $attributes = $client->verifyIdToken($token->id_token, CLIENT_ID) | ||
| 118 | ->getAttributes(); | ||
| 119 | $gplus_id = $attributes["payload"]["sub"]; | ||
| 120 | |||
| 121 | |||
| 122 | // Store the token in the session for later use. | ||
| 123 | $app['session']->set('token', json_encode($token)); | ||
| 124 | $response = 'Successfully connected with token: ' . print_r($token, true); | ||
| 125 | } else { | ||
| 126 | $response = 'Already connected'; | ||
| 127 | } | ||
| 128 | |||
| 129 | return new Response($response, 200); | ||
| 130 | }); | ||
| 131 | |||
| 132 | // Get list of activities visible to this app. | ||
| 133 | $app->get('/activities', function () use ($app, $client, $plus) { | ||
| 134 | $token = $app['session']->get('token'); | ||
| 135 | |||
| 136 | //if (empty($token)) { | ||
| 137 | //return new Response('Unauthorized request', 401); | ||
| 138 | //} | ||
| 139 | |||
| 140 | $client->setAccessToken($token); | ||
| 141 | $activities = $plus->activities->listActivities('me', 'public', array()); | ||
| 142 | |||
| 143 | /* | ||
| 144 | * Note (Gerwin Sturm): | ||
| 145 | * $app->json($activities) ignores the $activities->items not returning this array | ||
| 146 | * Probably needs to be fixed in the Client Library | ||
| 147 | * Using ->toSimpleObject for now to get a JSON-convertible object | ||
| 148 | */ | ||
| 149 | return $app->json($activities->toSimpleObject()); | ||
| 150 | }); | ||
| 151 | |||
| 152 | // Revoke current user's token and reset their session. | ||
| 153 | $app->post('/disconnect', function () use ($app, $client) { | ||
| 154 | //error_log(print_r($app, true)); | ||
| 155 | $token = json_decode($app['session']->get('token'))->access_token; | ||
| 156 | $client->revokeToken($token); | ||
| 157 | // Remove the credentials from the user's session. | ||
| 158 | $app['session']->set('token', ''); | ||
| 159 | unset($app); | ||
| 160 | unset($client); | ||
| 161 | unset($_SESSION); | ||
| 162 | session_start(); | ||
| 163 | session_destroy(); | ||
| 164 | session_unset(); | ||
| 165 | session_write_close(); | ||
| 166 | setcookie(session_name(),'',0,'/'); | ||
| 167 | session_regenerate_id(true); | ||
| 168 | error_log('destroy'); | ||
| 169 | |||
| 170 | |||
| 171 | return new Response('Successfully disconnected', 200); | ||
| 172 | }); | ||
| 173 | |||
| 174 | $app->run(); |
signinView.php
0 → 100644
| 1 | <!DOCTYPE HTML> | ||
| 2 | <script type="text/javascript"> | ||
| 3 | var auth2 = auth2 || {}; | ||
| 4 | |||
| 5 | (function() { | ||
| 6 | var po = document.createElement('script'); | ||
| 7 | po.type = 'text/javascript'; po.async = true; | ||
| 8 | po.src = 'https://plus.google.com/js/client:plusone.js?onload=startApp'; | ||
| 9 | var s = document.getElementsByTagName('script')[0]; | ||
| 10 | s.parentNode.insertBefore(po, s); | ||
| 11 | })(); | ||
| 12 | var CLIENT_ID = '326088686201-1llld5s7s3uhb2shl4g2g9djkvq584pc.apps.googleusercontent.com'; | ||
| 13 | |||
| 14 | /** | ||
| 15 | * Replace this with the client secret you got from the Google APIs console. | ||
| 16 | */ | ||
| 17 | var CLIENT_SECRET = 'F4Fa8MdTT17f4voG4lRaOCuc'; | ||
| 18 | |||
| 19 | /** | ||
| 20 | * Optionally replace this with your application's name. | ||
| 21 | */ | ||
| 22 | var APPLICATION_NAME = "banners.gotenzing.com"; | ||
| 23 | |||
| 24 | var STATE = "f4325120986c13bf5f55fbb8feab9105"; | ||
| 25 | |||
| 26 | </script> | ||
| 27 | <!-- JavaScript specific to this application that is not related to API | ||
| 28 | calls --> | ||
| 29 | <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js" ></script> | ||
| 30 | |||
| 31 | <style> | ||
| 32 | #customBtn { | ||
| 33 | width: 155px; | ||
| 34 | } | ||
| 35 | #customBtn:hover { | ||
| 36 | box-shadow: 2px 2px 3px #888888; | ||
| 37 | border-radius: 5px; | ||
| 38 | cursor: hand; | ||
| 39 | } | ||
| 40 | </style> | ||
| 41 | |||
| 42 | <div id="gConnect" > | ||
| 43 | <img id="customBtn" src="./signin_button.png" onClick="signInClick()" | ||
| 44 | alt="Sign in with Google+" /> | ||
| 45 | </div> | ||
| 46 | <div id="authOps" style="display:none"> | ||
| 47 | <?php | ||
| 48 | |||
| 49 | |||
| 50 | include('includes/loggedin.php'); | ||
| 51 | |||
| 52 | ?> | ||
| 53 | </div> | ||
| 54 | |||
| 55 | <script type="text/javascript"> | ||
| 56 | var helper = (function() { | ||
| 57 | var authResult = undefined; | ||
| 58 | |||
| 59 | return { | ||
| 60 | /** | ||
| 61 | * Hides the sign-in button and connects the server-side app after | ||
| 62 | * the user successfully signs in. | ||
| 63 | * | ||
| 64 | * @param {Object} authResult An Object which contains the access token and | ||
| 65 | * other authentication information. | ||
| 66 | */ | ||
| 67 | onSignInCallback: function(authResult) { | ||
| 68 | $('#authResult').html('Auth Result:<br/>'); | ||
| 69 | for (var field in authResult) { | ||
| 70 | $('#authResult').append(' ' + field + ': ' + authResult[field] + '<br/>'); | ||
| 71 | } | ||
| 72 | if (authResult['access_token']) { | ||
| 73 | // The user is signed in | ||
| 74 | this.authResult = authResult; | ||
| 75 | |||
| 76 | // After we load the Google+ API, render the profile data from Google+. | ||
| 77 | gapi.client.load('plus','v1',this.renderProfile); | ||
| 78 | |||
| 79 | // After we load the profile, retrieve the list of activities visible | ||
| 80 | // to this app, server-side. | ||
| 81 | helper.activities(); | ||
| 82 | } else if (authResult['error']) { | ||
| 83 | // There was an error, which means the user is not signed in. | ||
| 84 | // As an example, you can troubleshoot by writing to the console: | ||
| 85 | console.log('There was an error: ' + authResult['error']); | ||
| 86 | $('#authResult').append('Logged out'); | ||
| 87 | $('#authOps').hide('slow'); | ||
| 88 | $('#gConnect').show(); | ||
| 89 | } | ||
| 90 | console.log('authResult', authResult); | ||
| 91 | }, | ||
| 92 | /** | ||
| 93 | * Retrieves and renders the authenticated user's Google+ profile. | ||
| 94 | */ | ||
| 95 | |||
| 96 | |||
| 97 | renderProfile: function() { | ||
| 98 | |||
| 99 | var req = gapi.client.plus.people.get( {'userId' : 'me'} ); | ||
| 100 | var req = req.execute(handleEmailResponse); | ||
| 101 | |||
| 102 | |||
| 103 | var request = gapi.client.plus.people.get( {'userId' : 'me'} ); | ||
| 104 | request.execute(function(profile) { | ||
| 105 | $('#profile').empty(); | ||
| 106 | if (profile.error) { | ||
| 107 | $('#profile').append(profile.error); | ||
| 108 | return; | ||
| 109 | } | ||
| 110 | // console.log(people); | ||
| 111 | console.log('test'); | ||
| 112 | $('#profile').append( | ||
| 113 | $('<p><img src=\"' + profile.image.url + '\"></p>')); | ||
| 114 | $('#profile').append( | ||
| 115 | $('<p>Hello ' + profile.displayName + '!<br />Tagline: ' + | ||
| 116 | profile.tagline + '<br />About: ' + profile.aboutMe + '</p>')); | ||
| 117 | if (profile.cover && profile.coverPhoto) { | ||
| 118 | $('#profile').append( | ||
| 119 | $('<p><img src=\"' + profile.cover.coverPhoto.url + '\"></p>')); | ||
| 120 | } | ||
| 121 | }); | ||
| 122 | $('#authOps').show('slow'); | ||
| 123 | $('#gConnect').hide(); | ||
| 124 | }, | ||
| 125 | /** | ||
| 126 | * Calls the server endpoint to disconnect the app for the user. | ||
| 127 | */ | ||
| 128 | disconnectServer: function() { | ||
| 129 | // Revoke the server tokens | ||
| 130 | $.ajax({ | ||
| 131 | type: 'POST', | ||
| 132 | url: $(location).attr('origin') + '/signin.php/disconnect', | ||
| 133 | async: false, | ||
| 134 | success: function(result) { | ||
| 135 | console.log('revoke response: ' + result); | ||
| 136 | $('#authOps').hide(); | ||
| 137 | $('#profile').empty(); | ||
| 138 | $('#visiblePeople').empty(); | ||
| 139 | $('#authResult').empty(); | ||
| 140 | $('#gConnect').show(); | ||
| 141 | }, | ||
| 142 | error: function(e) { | ||
| 143 | console.log(e); | ||
| 144 | } | ||
| 145 | }); | ||
| 146 | }, | ||
| 147 | /** | ||
| 148 | * Calls the server endpoint to connect the app for the user. The client | ||
| 149 | * sends the one-time authorization code to the server and the server | ||
| 150 | * exchanges the code for its own tokens to use for offline API access. | ||
| 151 | * For more information, see: | ||
| 152 | * https://developers.google.com/+/web/signin/server-side-flow | ||
| 153 | */ | ||
| 154 | connectServer: function(code) { | ||
| 155 | console.log(code); | ||
| 156 | $.ajax({ | ||
| 157 | type: 'POST', | ||
| 158 | url: $(location).attr('origin') + '/signin.php/connect?state='+STATE, | ||
| 159 | contentType: 'application/octet-stream; charset=utf-8', | ||
| 160 | success: function(result) { | ||
| 161 | console.log(result); | ||
| 162 | helper.activities(); | ||
| 163 | onSignInCallback(auth2.currentUser.get().getAuthResponse()); | ||
| 164 | }, | ||
| 165 | error: function(result){ | ||
| 166 | console.log(result); | ||
| 167 | }, | ||
| 168 | processData: false, | ||
| 169 | data: code | ||
| 170 | }); | ||
| 171 | }, | ||
| 172 | /** | ||
| 173 | * Calls the server endpoint to get the list of activities visible to this | ||
| 174 | * app. | ||
| 175 | * @param success Callback called on success. | ||
| 176 | * @param failure Callback called on error. | ||
| 177 | */ | ||
| 178 | activities: function(success, failure) { | ||
| 179 | success = success || function(result) { helper.appendActivity(result); }; | ||
| 180 | $.ajax({ | ||
| 181 | type: 'GET', | ||
| 182 | url: $(location).attr('origin') + '/signin.php/activities', | ||
| 183 | contentType: 'application/octet-stream; charset=utf-8', | ||
| 184 | success: success, | ||
| 185 | error: failure, | ||
| 186 | processData: false | ||
| 187 | }); | ||
| 188 | }, | ||
| 189 | /** | ||
| 190 | * Displays visible People retrieved from server. | ||
| 191 | * | ||
| 192 | * @param {Object} activities A list of Google+ activity resources. | ||
| 193 | */ | ||
| 194 | appendActivity: function(activities) { | ||
| 195 | $('#activities').empty(); | ||
| 196 | |||
| 197 | |||
| 198 | |||
| 199 | }, | ||
| 200 | }; | ||
| 201 | })(); | ||
| 202 | |||
| 203 | /** | ||
| 204 | * Perform jQuery initialization and check to ensure that you updated your | ||
| 205 | * client ID. | ||
| 206 | */ | ||
| 207 | $(document).ready(function() { | ||
| 208 | $('#disconnect').click(helper.disconnectServer); | ||
| 209 | if ($('[data-clientid="YOUR_CLIENT_ID"]').length > 0) { | ||
| 210 | alert('This sample requires your OAuth credentials (client ID) ' + | ||
| 211 | 'from the Google APIs console:\n' + | ||
| 212 | ' https://code.google.com/apis/console/#:access\n\n' + | ||
| 213 | 'Find and replace YOUR_CLIENT_ID with your client ID and ' + | ||
| 214 | 'YOUR_CLIENT_SECRET with your client secret in the project sources.' | ||
| 215 | ); | ||
| 216 | } | ||
| 217 | }); | ||
| 218 | |||
| 219 | /** | ||
| 220 | * Called after the Google client library has loaded. | ||
| 221 | */ | ||
| 222 | function startApp() { | ||
| 223 | gapi.load('auth2', function(){ | ||
| 224 | |||
| 225 | // Retrieve the singleton for the GoogleAuth library and setup the client. | ||
| 226 | gapi.auth2.init({ | ||
| 227 | client_id: CLIENT_ID, | ||
| 228 | cookiepolicy: 'single_host_origin', | ||
| 229 | fetch_basic_profile: false, | ||
| 230 | scope: 'https://www.googleapis.com/auth/userinfo.email' | ||
| 231 | }).then(function (){ | ||
| 232 | console.log('init'); | ||
| 233 | auth2 = gapi.auth2.getAuthInstance(); | ||
| 234 | auth2.then(function() { | ||
| 235 | var isAuthedCallback = function () { | ||
| 236 | onSignInCallback(auth2.currentUser.get().getAuthResponse()) | ||
| 237 | } | ||
| 238 | helper.activities(isAuthedCallback); | ||
| 239 | }); | ||
| 240 | }); | ||
| 241 | }); | ||
| 242 | } | ||
| 243 | |||
| 244 | /** | ||
| 245 | * Either signs the user in or authorizes the back-end. | ||
| 246 | */ | ||
| 247 | function signInClick() { | ||
| 248 | var signIn = function(result) { | ||
| 249 | auth2.signIn().then( | ||
| 250 | function(googleUser) { | ||
| 251 | onSignInCallback(googleUser.getAuthResponse()); | ||
| 252 | }, function(error) { | ||
| 253 | alert(JSON.stringify(error, undefined, 2)); | ||
| 254 | }); | ||
| 255 | }; | ||
| 256 | |||
| 257 | var reauthorize = function() { | ||
| 258 | auth2.grantOfflineAccess().then( | ||
| 259 | function(result){ | ||
| 260 | helper.connectServer(result.code); | ||
| 261 | }); | ||
| 262 | }; | ||
| 263 | |||
| 264 | helper.activities(signIn, reauthorize); | ||
| 265 | } | ||
| 266 | |||
| 267 | /** | ||
| 268 | * Calls the helper method that handles the authentication flow. | ||
| 269 | * | ||
| 270 | * @param {Object} authResult An Object which contains the access token and | ||
| 271 | * other authentication information. | ||
| 272 | */ | ||
| 273 | function handleEmailResponse(resp) { | ||
| 274 | var primaryEmail; | ||
| 275 | for (var i=0; i < resp.emails.length; i++) { | ||
| 276 | if (resp.emails[i].type === 'account') primaryEmail = resp.emails[i].value; | ||
| 277 | } | ||
| 278 | var domain = primaryEmail.substring(primaryEmail.lastIndexOf("@") +1); | ||
| 279 | |||
| 280 | if(domain != 'gotenzing.com'){ | ||
| 281 | $(document).ready(function() { | ||
| 282 | $.ajax({ | ||
| 283 | type: 'POST', | ||
| 284 | url: $(location).attr('origin') + '/signin.php/disconnect', | ||
| 285 | async: false, | ||
| 286 | success: function(result) { | ||
| 287 | console.log('revoke response: ' + result); | ||
| 288 | $('#authOps').hide(); | ||
| 289 | $('#profile').empty(); | ||
| 290 | $('#visiblePeople').empty(); | ||
| 291 | $('#authResult').empty(); | ||
| 292 | $('#gConnect').show(); | ||
| 293 | $('authOps').empty(); | ||
| 294 | }, | ||
| 295 | error: function(e) { | ||
| 296 | console.log(e); | ||
| 297 | } | ||
| 298 | }); | ||
| 299 | }); | ||
| 300 | } | ||
| 301 | |||
| 302 | |||
| 303 | |||
| 304 | console.log( domain); | ||
| 305 | } | ||
| 306 | |||
| 307 | |||
| 308 | |||
| 309 | function onSignInCallback(authResult) { | ||
| 310 | helper.onSignInCallback(authResult); | ||
| 311 | } | ||
| 312 | |||
| 313 | |||
| 314 | </script> | ||
| 315 |
signin_button.png
0 → 100644
3.02 KB
-
Please register or sign in to post a comment