Skip to content

bvrignaud/ci-fb-ion-auth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ci-fb-ion-auth

This is a php and CodeIgniter (3.x) library to use Facebook php SDK with Ion-Auth.

Requirements

Installation

Install the Facebook PHP SDK with Composer with composer install (Read more) :

$ cd /path/to/codeigniter_project/
$ composer require facebook/graph-sdk

In your CodeIgniter /application/config/config.php file, set $config['composer_autoload'] to TRUE. Read more.

Copy the files from this package to the corresponding folder in your application folder. For example, copy application/config/facebook.php to application/config/facebook.php

You can also copy the libraries and models directories into your third_party/ci-fb-ion-auth folder. For example, copy to /application/third_party/ci-fb-ion-auth/. The directory structure would be :

config/facebook.php
third_party/ci-fb-ion-auth/helpers/facebook_helper.php
third_party/ci-fb-ion-auth/libraries/Facebook.php
third_party/ci-fb-ion-auth/models/Facebook_model.php

Only the library, model and config files are required.

Edit your facebook.php config file in /application/config/facebook.php with your Facebook App details.

Autoload the library in application/config/autoload.php or load it in needed controllers with $this->load->library('facebook');.

Autoload the helper in application/config/autoload.php or load it in needed controllers with $this->load->helper('facebook_helper');.

Relational DB Setup

Run the SQL file sql/ci-fb-ion-auth.

Usage

In the package you will find simple example usage code in the controllers and views folders.

Register with Facebook

view:

<a href="<?=getFacebookLoginUrl('welcome/fb_register_callback')?>">Register with Facebook</a>

controller (welcome.php):

public function fb_register_callback()
{
    if ($this->facebook->fb_callback()) {
        redirect('user/account');
    } else {
        show_error('erreur');
    }
}

Connexion with Facebook

view:

<a href="<?=getFacebookLoginUrl('welcome/fb_login_callback')?>">Connexion with Facebook</a>

controller (welcome_fb_ion_auth.php):

public function fb_login_callback()
{
    if ($this->facebook->fb_callback()) {
        echo 'Your are now logged in !";
    } else {
        show_error('erreur');
    }
}

Connect/Disconnect user's Facebook account

view :

if ($this->ion_auth->logged_in()) {
    if ($this->ion_auth->user()->row()->idfacebook_user) {
        echo '<a href="'.site_url('welcome/disconnectFacebookAccount_callback')."
                onclick="return confirm(\'Are you sure you want to disconnect your facebook account from this application ?\')">
                 Disconnect my Facebook account
            </a>';
    } else {
        echo '<a href="'.getFacebookLoginUrl('welcome/connectFacebookAccount_callback').'">
                  Connect my Facebook account
              </a>';
    }
}

controller (welcome.php):

public function disconnectFacebookAccount_callback()
{
    $this->facebook->disconnectFacebookAccount();
    redirect();
}

public function connectFacebookAccount_callback()
{
    $this->facebook->connectFacebookAccount();
    redirect();
}

About

Facebook library for CodeIgniter with Ion-Auth

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages