0

I decided to handle the Facebook functionality into a component I wrote the following code to start my own Facebook component:

<?php
class FacebookComponent extends Object{
  var $name = 'Facebook';
 // var $components = array('Auth', 'Session');
  var $settings = array();
  var $controller = null;
  var $facebook;
  var $fbUid;

  function initialize(&$controller, $settings) {
    Configure::load('app.conf');
    App::import('Vendor', 'Facebook', array('file' => 'facebook/src/facebook.php'));
    $this->facebook = new Facebook(array(
        'appId' => Configure::read('FBappId'),
        'secret' => Configure::read('FBsecret')
    ));

    $this->fbUid = $this->facebook->getUser();  
  }

  function is_user(){
    if ($this->fbUid){
      return true;
    }
    else{
      return false;
    }   
  }
  function getLoginUrl(){
      return $this->facebook->getLoginUrl(array( 'scope' => 'publish_stream'));
    }

}

?>

Everything about auth component and the login action of users controller works fine without using the above component in users_controller.php. However, just adding the Facebook component of mine in the components list of users_controller.php via var $components, I find that login action acts in strange way:

function login(){       
      if (!$this->Auth->user()){
        if (empty($this->data['User']['username'])){         
          $this->Session->setFlash(__('You have to login', true), 'error_msg');
        }
        else{
          $this->Session->setFlash(__('bad login', true), 'error_msg');

        }

      }
      else{
        $this->Session->setFlash(__('correct login', true), 'done_msg');
      }
}

when I try to access any protected action of any controller by the Auth component, I get the login page with the message of the correct login and after re-logging again it redirects to the home page of the website.

There is another symptoms, I have navigation element which shows logout link if the user is logged in, it does not show this link on any part of the website except the login page

<?php if ($session->read('Auth.User.id')): ?>
    <li><?php echo $html->link($html->image('close.png') . __('logout', true), array('controller' => 'users', 'action' => 'logout', 'admin' => false), array(), null, false); ?></li>
  <?php endif; ?>

I'm Using CakePHP 1.2.10 and Facebook PHP SDK (v.3.0.0) -from vendors-. I'd like to confirm that every thing go fine without the component. What's the problem?

4

0 に答える 0