private function createUserProfile(FacebookSession $session, GraphUser $user)
 {
     $profile = new UserProfile();
     $profilePicReq = new FacebookRequest($session, 'GET', '/me/picture', ['redirect' => 0, 'type' => 'large']);
     $pic = $profilePicReq->execute()->getGraphObject()->asArray();
     $profile['displayName'] = $user->getName();
     $profile['profileUrl'] = $user->getLink();
     $profile['imageUrl'] = $pic['url'];
     //TODO other props
     return $profile;
 }
Beispiel #2
0
 /**
  * Register user using facebook data. It will also check if email already exists and it will update that user.
  * @param GraphUser $me
  * @return User|null
  */
 public static function facebookRegister(GraphUser $me)
 {
     // 1. check if email already exists.
     $old = self::findByAttributes(array('email' => $me->getEmail()));
     if ($old) {
         /* @var $old User */
         $old->fb_id = $me->getId();
         if ($old->status == self::STATUS_NEW) {
             $old->status = self::STATUS_ACTIVE;
         }
         $old->save(false);
         UserConfig::set('FACEBOOK_NAME', $me->getFirstName() . ' ' . $me->getMiddleName() . ' ' . $me->getLastName(), $old->id);
         UserConfig::set('FACEBOOK_EMAIL', $me->getProperty('email'), $old->id);
         UserConfig::set('FACEBOOK_PROFILE', $me->getLink(), $old->id);
         return $old;
     }
     $user = new User();
     $user->fb_id = $me->getId();
     $user->email = $me->getProperty('email');
     $user->register_date = date('Y-m-d H:i:s');
     $user->status = self::STATUS_ACTIVE;
     $user->save(false);
     UserConfig::set('FACEBOOK_NAME', $me->getFirstName() . ' ' . $me->getMiddleName() . ' ' . $me->getLastName(), $user->id);
     UserConfig::set('FACEBOOK_EMAIL', $me->getProperty('email'), $user->id);
     UserConfig::set('FACEBOOK_PROFILE', $me->getLink(), $user->id);
     return $user;
 }