Skip to content

Commit

Permalink
add 2 examples Sign-in/Sign-up users and Basic Facebook in
Browse files Browse the repository at this point in the history
  • Loading branch information
hybridauth committed Nov 22, 2011
1 parent ad23b4d commit f6975d6
Show file tree
Hide file tree
Showing 25 changed files with 970 additions and 34 deletions.
90 changes: 90 additions & 0 deletions examples/facebook_integration/index.php
@@ -0,0 +1,90 @@
<?php
session_start();

$config = dirname(__FILE__) . '/../../hybridauth/config.php';
require_once( "../../hybridauth/Hybrid/Auth.php" );

if( isset( $_GET["login"] ) ){
try{
// hybridauth EP
$hybridauth = new Hybrid_Auth( $config );

$adapter = $hybridauth->authenticate( "facebook" );

$user_profile = $adapter->getUserProfile();
}
catch( Exception $e ){
die( "<b>got an error!</b> " . $e->getMessage() );
}
}

if( ! isset( $user_profile ) ){
?>
<p>
A basic example which show how to integrate Facebook Dialogs and stuff on your website side by side whith HybridAuth. Click the Signin link to start.
</p>

<h2><a href ="index.php?login=1">Signin with facebook</a></h2>

<img src="../fb.gif" style="border:1px solid #ccc;padding:4px;" />
<?php
}
else{
?>
<h3>Hi <?php echo $user_profile->displayName; ?> </h3>

<input value="Want to share this page on facebook?" style="height:30px;" type="submit" onclick="share_link()" />
<input value="Want to publish a random story your facebook wall?" style="height:30px;" type="submit" onclick="post_to_wall()" />
<input value="Want to invite some friends ?" style="height:30px;" type="submit" onclick="invite_friends()" />

<p>
<hr />
The invite friends <b>may require some advanced</b> facebook application configuration your side. To know more about FB.ui visit https://developers.facebook.com/docs/reference/javascript/FB.ui/
</p>

<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
FB.init({
appId:'<?php echo $adapter->config["keys"]["id"]; ?>', // or simply set your appid hard coded
cookie:true,
status : true,
xfbml:true
});

// https://developers.facebook.com/docs/reference/dialogs/send/
function share_link() {
FB.ui({
method: 'send',
name: 'HybridAuth, open source social sign on php library',
link: 'http://hybridauth.sourceforge.net/',
});
}

// https://developers.facebook.com/docs/reference/dialogs/requests/
function invite_friends() {
FB.ui({
method: 'apprequests', message: '<?php echo $user_profile->displayName; ?> want you to join him at mywebsite.com.'
});
}

// https://developers.facebook.com/docs/reference/dialogs/feed/
function post_to_wall() {
var obj = {
method: 'feed',
link: 'http://hybridauth.sourceforge.net/',
picture: 'http://fbrell.com/f8.jpg',
name: 'HybridAuth',
caption: 'HybridAuth, open source social sign on php library',
description: 'HybridAuth, open source social sign on php library.'
};

function callback(response) {
document.getElementById('msg').innerHTML = "Post ID: " + response['post_id'];
}

FB.ui(obj, callback);
}
</script>
<?php
}
Binary file added examples/fb.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 2 additions & 4 deletions examples/hello_world/index.php
@@ -1,11 +1,9 @@
<?php
session_start();

session_name("foo");
session_start();

// config and includes
$config = dirname(__FILE__) . '/../../hybridauth/config.php';
require_once( "../../hybridauth/Hybrid/Auth.php" );
require_once( "../../hybridauth/Hybrid/Auth.php" );

try{
// hybridauth EP
Expand Down
84 changes: 62 additions & 22 deletions examples/index.html
@@ -1,41 +1,79 @@
<center>
<br />
<h1><u>HybridAuth examples and demos</u></h1>
<table width="60%" border="0" cellspacing="10">
<tr>
<td width="33%" align="center"><a href="hello_world/index.php"><h3>Hello world</h3></a></td>
<td align="center"><a href="widget_authentication/index.php"><h3>Widget integration</h3></a></td>
<td width="33%" align="center"><a href="social_hub/login.php"><h3>Tiny Social Hub</h3></a></td>
</tr>
<tr>
<td align="center"><a href="hello_world/index.php"><img src="helloworld.gif" width="250" style="border:1px solid #ccc;padding:4px;" /></a></td>
<td align="center"><a href="widget_authentication/index.php"><img src="widget.gif" width="250" style="border:1px solid #ccc;padding:4px;" /></a></td>
<td align="center"><a href="social_hub/index.php"><img src="embed.gif" width="250" style="border:1px solid #ccc;padding:4px;" /></a></td>
</tr>
</table>

<br />

<table width="630" border="0" cellspacing="10">
<table width="80%" border="0" cellspacing="10">
<tr>
<td>
<hr />
<h2>Getting Started</h2>
<p align="justify">To install HybridAuth, you can use the <a href="../install/">HybridAuth Auto Installer</a></p>
<h2>Getting Started</h2>
<p align="justify">To install HybridAuth, you can use the <a href="../hybridauth/install.php">HybridAuth Auto Installer</a></p>

<p align="justify">You can also install HybridAuth manually by refering to <strong>Installation and Configuration</strong> sections at <a href="http://hybridauth.sourceforge.net/userguide.html">http://hybridauth.sourceforge.net/userguide.html</a></p>

<p align="justify">We also highly recommend to download and use <b>the latest release</b> from HybridAuth website at <a href="http://hybridauth.sourceforge.net/download.html"></a><a href="http://hybridauth.sourceforge.net/download.html">http://hybridauth.sourceforge.net/download.html</a> </p>

<p><strong>To get help and support</strong>, join us and participate in the hybridauth discussion group at <a href="http://hybridauth.sourceforge.net/support.html"></a><a href="http://hybridauth.sourceforge.net/support.html">http://hybridauth.sourceforge.net/support.html</a></p>
<hr />
</td>
</tr>
</table>
</table>
</center>



<center>
<h2><u>HybridAuth Examples and Demos</u></h2>
<table width="60%" border="0" cellspacing="10">

<tr>
<td width="280" align="center"><a href="hello_world/index.php"><img src="helloworld.gif" width="250" style="border:1px solid #ccc;padding:4px;" /></a></td>
<td align="left" valign="top"><a href="hello_world/index.php"><b>1 - Hello world</b></a>
<p align="justify">
A very simple sign-in script which will try to directly connect the user with Twitter then grab his complete profile and also access the twitter social api.
How this script work is well <a href="http://hybridauth.sourceforge.net/userguide/Integrating_HybridAuth_SignIn.html">explained in this online guide</a>.
</p>
</td>
</tr>

<tr>
<td align="center"><a href="widget_authentication/index.php"><img src="widget.gif" width="250" style="border:1px solid #ccc;padding:4px;" /></a></td>
<td align="left" valign="top"><a href="widget_authentication/index.php"><b>2 - Widget integration</b></a>
<p align="justify">
A simple user friendly sign-in interface (aka: provider selector UI) which you can integrate, customize, redesign and improve (and hopefully you will share some of your work with the comminuty).
</p>
</td>
</tr>

<tr>
<td align="center"><a href="social_hub/index.php"><img src="embed.gif" width="250" style="border:1px solid #ccc;padding:4px;" /></a></td>
<td align="left" valign="top"><a href="social_hub/index.php"><b>3 - Tiny Social Hub</b></a>
<p align="justify">
This exapmle show how users can login with providers using HybridAuth. It also show how to grab their profile, update their status or to grab their freinds list from services such as facebook, twitter, myspace.
</p>
</tr>

<tr>
<td align="center"><a href="signin_signup/index.php"><img src="singup.gif" width="250" style="border:1px solid #ccc;padding:4px;" /></a></td>
<td align="left" valign="top"><a href="signin_signup/index.php"><b>4 - Sign-in/Sign-up users</b></a>
<p align="justify">
An attempt to put together an answer to how to sign-in/sign-up users using HybridAuth in an existing web application. <p align="justify">
This exapmle provide a simple implementation of the whole sign-in/sign-up process on a MVC environment.</p>
</tr>

<tr>
<td align="center"><a href="facebook_integration/index.php"><img src="fb.gif" width="250" style="border:1px solid #ccc;padding:4px;" /></a></td>
<td align="left" valign="top"><a href="facebook_integration/index.php"><b>5 - Basic Facebook integration</b></a>
<p align="justify">
A basic example which show how to integrate Facebook Dialogs and stuff on your website side by side whith HybridAuth.
</p>
</tr>

</table>
</center>
<br />
<br />

<hr />
<p>HybridAuth Open Source Social Sign On Library, 2011.</p>

<script type="text/javascript">
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
Expand All @@ -47,3 +85,5 @@ <h2>Getting Started</h2>
} catch(err) {}</script>
<script type="text/javascript"> var sc_project=7312365; var sc_invisible=1; var sc_security="30da00f3"; </script>
<script type="text/javascript" src="http://www.statcounter.com/counter/counter.js"></script>
</body>
</html>
35 changes: 35 additions & 0 deletions examples/signin_signup/application.config.php
@@ -0,0 +1,35 @@
<?php
// load hybridauth base file, change the following paths if necessary
// note: in your application you probaly you have to include these only when required..
$hybridauth_config = dirname(__FILE__) . '/../../hybridauth/config.php';
require_once( "../../hybridauth/Hybrid/Auth.php" );

// database config
$database_host = "localhost";
$database_user = "root";
$database_pass = "";
$database_name = "hybridauth_test";

$database_link = @ mysql_connect( $database_host, $database_user, $database_pass );

if ( ! $database_link ) {
die( "This sample require a mysql database. Please edit the configuration file: <b>application.config.php</b>. <hr><b>Mysql error</b>: " . mysql_error() );
}

$db_selected = mysql_select_db( $database_name );

if ( ! $db_selected ) {
die( "This sample require a mysql database. Please edit the configuration file: <b>application.config.php</b>. <hr><b>Mysql error</b>: " . mysql_error() );
}

function mysql_query_excute( $sql ){
$result = mysql_query($sql);

if (!$result) {
$message = 'Invalid query: ' . mysql_error() . "\n";
$message .= 'Whole query: ' . $sql;
die($message);
}

return $result;
}
58 changes: 58 additions & 0 deletions examples/signin_signup/application/base.php
@@ -0,0 +1,58 @@
<?php
// almost nothing to see here... just basic mvc stuff
class application
{
public $uri;

function __construct( $uri = null )
{
$this->uri = $uri;

$this->loadController( $uri['controller'] );
}

function loadController( $class )
{
$file = "application/controllers/".$this->uri['controller'].".php";

if(!file_exists($file)) die( "controller not found at $file" );

require_once($file);

$controller = new $class();

if( method_exists( $controller, $this->uri['method'] ) ){
$controller->{$this->uri['method']}( $this->uri['var'] );
}
else {
$controller->index();
}
}
}

class model
{
function __construct(){}
}

class controller
{
function loadModel( $model )
{
require_once( 'application/models/'. $model .'.php' );
return new $model;
}

function loadView( $view, $vars="" )
{
if(is_array($vars) && count($vars) > 0) extract($vars, EXTR_PREFIX_SAME, "wddx");
require_once( 'application/views/'.$view.'.html' );
}

function redirect( $uri )
{
header( "Location: index.php?route=$uri" );

die();
}
}

0 comments on commit f6975d6

Please sign in to comment.