Пример #1
0
 /** @return facebook info */
 function getFbProfile($fieldName)
 {
     if (is_null($this->fbProfile) && $this->getFbUid()) {
         $session = $this->getFacebookJsSession();
         $fbReq = new FacebookRequest($session, 'GET', '/me');
         try {
             $user_profile = $fbReq->execute()->getGraphObject(GraphUser::className());
             $this->fbProfile = $user_profile;
         } catch (Exception $e) {
             return null;
         }
     }
     return $this->fbProfile->getProperty($fieldName);
 }
 /**
  * Retourne un utilisateur de la base en fonction de l'utilisateur facebook
  * Si il n'existe pas, on en créée un
  * @param  GraphUser $user [description]
  * @return [type]          [description]
  */
 public function getUserFromFacebook(GraphUser $user)
 {
     $email = $user->getEmail();
     if (is_null($email)) {
         throw new \Exception('Facebook user does not share email', 400);
     }
     // Get user from email
     $fos_user = $this->user_manager->findUserByEmail($email);
     // Create user if necessary
     if (is_null($fos_user)) {
         $fos_user = $this->user_manager->createUser();
     }
     $fos_user->setEnabled(true);
     $fos_user->setEmail($email);
     $fos_user->setFirstName($user->getFirstName());
     $fos_user->setLastName($user->getLastName());
     $fos_user->setRoles([$this->user_role]);
     $fos_user->setFacebookId($user->getId());
     $fos_user->setLocale(substr($user->getProperty('locale'), 0, 2));
     $fos_user->setTimezone($user->getTimezone());
     $this->user_manager->updateCanonicalFields($fos_user);
     $this->user_manager->updateUser($fos_user);
     return $fos_user;
 }
Пример #3
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;
 }
Пример #4
0
 /**
  * OVERRIDE THIS IF NECESSARY
  *
  * @param GraphUser $facebook_user
  */
 public function createFacebookUser(GraphUser $facebook_user)
 {
     $fb_id_field = \Config::get('api-foundation::user_table_fb_id_field');
     $login_type_field = \Config::get('api-foundation::user_table_login_type_field');
     $login_type_facebook = \Config::get('api-foundation::user_table_login_type_facebook');
     $user = new OAuthUser();
     $user->email = $facebook_user->getProperty('email');
     $user->password = Hash::make(str_random(20));
     $user->{$fb_id_field} = $facebook_user->getId();
     $user->first_name = $facebook_user->getFirstName();
     $user->last_name = $facebook_user->getLastName();
     $user->{$login_type_field} = $login_type_facebook;
     $user->save();
 }