Skip to content
This repository was archived by the owner on Jul 8, 2023. It is now read-only.

Commit fce644d

Browse files
author
Stig Lindqvist
committed
Added facebook connect module
1 parent b4b1028 commit fce644d

27 files changed

+3664
-0
lines changed

facebookconnect/LICENSE

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Copyright (c) 2010, Will Rossiter
2+
All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without
5+
modification, are permitted provided that the following conditions are met:
6+
* Redistributions of source code must retain the above copyright
7+
notice, this list of conditions and the following disclaimer.
8+
* Redistributions in binary form must reproduce the above copyright
9+
notice, this list of conditions and the following disclaimer in the
10+
documentation and/or other materials provided with the distribution.
11+
* Neither the name of the organization nor the
12+
names of its contributors may be used to endorse or promote products
13+
derived from this software without specific prior written permission.
14+
15+
THIS SOFTWARE IS PROVIDED BY WILL ROSSITER ''AS IS'' AND ANY
16+
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18+
DISCLAIMED. IN NO EVENT SHALL Will Rossiter BE LIABLE FOR ANY
19+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

facebookconnect/README.md

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
# Facebook Connect Integration Module
2+
3+
## Maintainer Contact
4+
* Will Rossiter
5+
<will (at) fullscreen (dot) io>
6+
7+
## Requirements
8+
* SilverStripe 3.0
9+
10+
## Overview
11+
12+
The module provides a **basic** interface for implementing Facebook connect on
13+
a website. Facebook connect allows users to login to your website using their
14+
Facebook account. This module integrates that single sign-on within the existing
15+
SilverStripe member system.
16+
17+
This has been designed to use the Javascript SDK rather than the OAuth interface.
18+
19+
### What it provides
20+
21+
* Loads and setups Facebook Connect for Single Sign on via the Javascript SDK
22+
23+
* Authenticates users visiting the site - if they are logged into Facebook then
24+
you can access their information via the following controls. You can also
25+
optionally set whether to save visitors information as members on your site
26+
(for example if you need to cache their information)
27+
28+
If you haven't disabled the FacebookConnect::$create_member variable you can
29+
access the Facebook's member information by using:
30+
31+
```
32+
<% control CurrentMember %>
33+
$FirstName $LastName $Avatar(small)
34+
<% end_control %>
35+
```
36+
37+
If you have disabled the creation of members you can use the Facebook specific
38+
member control. This still returns a member object the only difference is that
39+
it won't save the information to the database
40+
41+
```
42+
<% control CurrentFacebookMember %>
43+
$FirstName $LastName $Avatar(small)
44+
<% end_control %>
45+
```
46+
47+
### What it does not provide (yet)
48+
49+
* This current iteration only provides the backbone. In future updates I am aiming
50+
to integrate things like publishing stories to a users wall, interacting with events,
51+
groups and other things like friends.
52+
* More controls over the logged in members information (eg status updates, events,
53+
groups). If you need this functionality you can build this on top of the Facebook API
54+
which is exposed:
55+
56+
```php
57+
function foo() {
58+
// returns the likes
59+
$likes = $this->getFacebook()->api('/me/likes');
60+
}
61+
```
62+
63+
### How to use
64+
65+
* To setup Facebook connect your first need to download this and put it in your
66+
SilverStripe sites root folder.
67+
* You need to register your website / application at
68+
https://developers.facebook.com/apps/?action=create
69+
* Once you have registered your app set the following in your mysite/_config.php
70+
file. Replace the values with the ones you should get after registering your app.
71+
72+
```php
73+
FacebookConnect::set_app_id('app-id');
74+
FacebookConnect::set_api_secret('api-secret');
75+
FacebookConnect::set_lang('en_US');
76+
```
77+
78+
* Update the database by running `/dev/build` to add the additional fields to
79+
the `Member` table.
80+
81+
* Include the `ConnectInit.ss` template in the `<body>` part of every site you
82+
wish to call a Facebook function. This includes the Facebook JavaScript SDK.
83+
E.g. on `FrontendPage.ss`
84+
85+
```
86+
<body>
87+
<% include ConnectInit %>
88+
```
89+
90+
Once you have done that you should be able to use the includes provided in this module.
91+
92+
```
93+
<% if CurrentFacebookMember %>
94+
<p>Hi $CurrentFacebookMember.FirstName</p>
95+
<% include ConnectLogout %>
96+
<% else %>
97+
<% include ConnectLogin %>
98+
<% end_if %>
99+
```
100+
101+
You can also access the Facebook member information in your PHP code. The Facebook API
102+
connection and current member are cached on the controller object. So for example if
103+
this is in your Page_Controller class
104+
105+
```php
106+
// returns the current facebook member (wrapped in a SS Member Object)
107+
$this->getCurrentFacebookMember();
108+
109+
// returns the API connection which you can use to write your own query
110+
$this->getFacebook();
111+
```
112+
113+
### License
114+
115+
Released under the BSD License.
116+

facebookconnect/_config.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
// configuration for facebook connect. You should not edit any of these
4+
// values and instead override from the mysite/_config file
5+
6+
require_once(dirname(__FILE__) . "/thirdparty/facebook-php-sdk/src/facebook.php");
7+
8+
// adds an extension hook to member
9+
DataObject::add_extension('Member', 'FacebookMember');
10+
11+
// adds the authenticator to the built in login form
12+
Authenticator::register('FacebookAuthenticator');
13+
14+
// add the facebook controller
15+
DataObject::add_extension('Controller', 'FacebookConnect');
16+
17+
// don't forget to add Facebook App Keys to mysite/_config.php
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
/**
4+
* Facebook Connect Authenicator. Provides a tab in {@link Security::login()}
5+
*
6+
* @package facebookconnect
7+
*/
8+
9+
class FacebookAuthenticator extends Authenticator {
10+
11+
/**
12+
* Authentication is handled by Facebook rather than us this needs to
13+
* return the new member object which is created. Creation of the member
14+
* is handled by {@link FacebookConnect::onBeforeInt()}
15+
*
16+
* @return false|Member
17+
*/
18+
public static function authenticate($RAW_data, Form $form = null) {
19+
return ($member = Member::currentMember()) ? $member : false;
20+
}
21+
22+
/**
23+
* Return the facebook login form
24+
*
25+
* @return Form
26+
*/
27+
public static function get_login_form(Controller $controller) {
28+
return Object::create("FacebookLoginForm", $controller, "FacebookLoginForm");
29+
}
30+
31+
/**
32+
* Return the name for the facebook tab
33+
*
34+
* @return String
35+
*/
36+
public static function get_name() {
37+
return _t('FacebookAuthenicator.TITLE', "Facebook Connect");
38+
}
39+
}

0 commit comments

Comments
 (0)