/**
  * Sync the new data from a users Facebook profile to the member database.
  *
  * @param GraphUser $result
  * @param bool $sync Flag to whether we override fields like first name
  */
 public function updateFacebookFields(GraphUser $result, $override = true)
 {
     $this->owner->FacebookLink = $result->getProperty('link');
     $this->owner->FacebookUID = $result->getProperty('id');
     $this->owner->FacebookTimezone = $result->getProperty('timezone');
     if ($override) {
         $email = $result->getProperty('email');
         if ($email && !$this->owner->Email || !Email::validEmailAddress($this->owner->Email)) {
             $this->owner->Email = $email;
         }
         $this->owner->FirstName = $result->getProperty('first_name');
         $this->owner->Surname = $result->getProperty('last_name');
     }
     $this->owner->extend('onUpdateFacebookFields', $result);
 }
 /**
  * Returns profile that created the album.
  *
  * @return GraphUser|null
  */
 public function getFrom()
 {
     return $this->getProperty('from', GraphUser::className());
 }
Esempio n. 3
0
 public function fb_login()
 {
     echo "sdxcxcfsdf";
     echo "i am here";
     $this->layout = 'ajax';
     FacebookSession::setDefaultApplication('195891030745689', '130d8f7bcae67a9a71d2c1c372896814');
     $helper = new FacebookRedirectLoginHelper(FACEBOOK_REDIRECT_URI);
     echo "=======";
     $session = $helper->getSessionFromRedirect();
     if (isset($_SESSION['token'])) {
         pr($_SESSION);
         echo "<<<<<<>>>>>>";
         $session = new FacebookSession($_SESSION['token']);
         try {
             echo "XXXXXXXXXX";
             $session->validate(FACEBOOK_APP_ID, FACEBOOK_APP_SECRET);
         } catch (FacebookAuthorizationException $e) {
             echo $e->getMessage();
         }
     }
     $data = array();
     $fb_data = array();
     if (isset($session)) {
         $_SESSION['token'] = $session->getToken();
         $request = new FacebookRequest($session, 'GET', '/me');
         $response = $request->execute();
         $graph = $response->getGraphObject(GraphUser::className());
         $fb_data = $graph->asArray();
         $id = $graph->getId();
         $image = "https://graph.facebook.com/" . $id . "/picture?width=100";
         if (!empty($fb_data)) {
             $result = $this->User->findByEmail($fb_data['email']);
             if (!empty($result)) {
                 if ($this->Auth->login($result['User'])) {
                     $this->Session->setFlash(FACEBOOK_LOGIN_SUCCESS, 'default', array('class' => 'message success'), 'success');
                     //$this->redirect(BASE_PATH);
                 } else {
                     $this->Session->setFlash(FACEBOOK_LOGIN_FAILURE, 'default', array('class' => 'message error'), 'error');
                     //$this->redirect(BASE_PATH.'login');
                 }
             } else {
                 $data['email'] = $fb_data['email'];
                 $data['first_name'] = $fb_data['first_name'];
                 $data['social_id'] = $fb_data['id'];
                 $data['picture'] = $image;
                 $data['uuid'] = String::uuid();
                 $this->User->save($data);
                 if ($this->User->save($data)) {
                     $data['id'] = $this->User->getLastInsertID();
                     if ($this->Auth->login($data)) {
                         $this->Session->setFlash(FACEBOOK_LOGIN_SUCCESS, 'default', array('class' => 'message success'), 'success');
                         //$this->redirect(BASE_PATH);
                     } else {
                         $this->Session->setFlash(FACEBOOK_LOGIN_FAILURE, 'default', array('class' => 'message error'), 'error');
                         //$this->redirect(BASE_PATH.'index');
                     }
                 } else {
                     $this->Session->setFlash(FACEBOOK_LOGIN_FAILURE, 'default', array('class' => 'message error'), 'error');
                     //$this->redirect(BASE_PATH.'index');
                 }
             }
         } else {
             $this->Session->setFlash(FACEBOOK_LOGIN_FAILURE, 'default', array('class' => 'message error'), 'error');
             //$this->redirect(BASE_PATH.'index');
         }
     }
 }
Esempio n. 4
0
<?php

require __DIR__ . '/../bootstrap/autoload.php';
$session = new \Facebook\FacebookSession('CAAGQHHX5SFkBAK0NhBmvPd62HSZC5dYjiopuJ5ZAqbYCCbs7y1ZBNNTsnZCK94aPXHvEYPzEEVNjGYgkX4ZBdndJPJ5mZAPFBfq7jQPcDkKTXT4zkrxWqEDUkwhYhshynonJqOEkX94OVBitQqln1jX9uW9vgNTzKfhPHGeZBXImPLloJ1skjTg0poGffRvp69rDj2EJejEXAsswFH9muSlf6WhgpOSv60ZD');
$me = (new \Facebook\FacebookRequest($session, 'GET', '/me'))->execute()->getGraphObject(GraphUser::className());