Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Discussion on login with Facebook in CakePHP

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 417
    Comment on it

    Hi Reader's,
    Welcome to FindNerd,today we are going to discuss login with Facebook in CakePHP.

    As we see that login with Facebook is very important feature for a web application because most of users do not take too much interest in signing up in any website. They want to use social media login for registration in any web application because with social medial login they can login just on a single click.

    So we are going to use cakePHP plugin for adding social medial login functionality in our CakePHP web application.

    We can follow below point for adding facebook login functionality in our web application.

    1-Download CakePHP Facebook Plugin from "github.com/webtechnick/CakePHP-Facebook-Plugin"

    Now  after downloading the plugin of facebook we have to move folder "app/plugins/facebook" also use Authcomponent CakePHP Facebook Plugin.

    2.After moving the plugin in cakePHP plugin folder we have to rename the file name like below

    "app/plugins/facebook/config/facebook.php."

     Now we have to create a facebook app in facebook website for our website. we have to add app key which should be run the facebook login in CakePHP.

    3.Now we have to add a another field "facebook_id" in our User table for storing user_id.

    4.we have to add below code in our User controller then Our controller will like below:

    <?php
        class UsersController extends AppController {
          var $name = 'Users';
          var $components = array('Facebook.Connect','Auth'); 
          var $helpers = array('Facebook.Facebook'); 
            function beforeFilter() {
                $this->Auth->loginRedirect = array('action' => 'index'); 
                $this->layout='facebook'; 
            }
            function index() { 
              }
            function login() { 
    
            }
    
            function logout() { 
             $this->Session->destroy();
             $this->redirect($this->Auth->logout());
            }
        }
    ?>

    we will use above code in:

    "Connect" component from Facebook Plugin and "Auth" from core files.
    "Facebook" helper from the Plugin.

    5-Now in the last we have to set view page for login which name is "login.ctp" where location will be below.

    "app/views/users/login.ctp"

    <?php
      echo $this->Facebook->login(array('width' => '174','height'=>'25','scope' => 'email'),
        __('Login with Facebook',true));
    ?>

    logout view will look like below code:

    <?php
      echo $this->Facebook->logout(array('redirect' => array('controller' => 'users', 'action' => 'logout')));
    ?>

     

     

     

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: