Ejemplo n.º 1
0
 /**
  * Create or update user by using data from facebook and login to store
  *
  * @param GraphUser   $facebookUser
  * @param AccessToken $accessToken
  *
  * @return CustomerInterface
  */
 private function createOrUpdateAndLogin(GraphUser $facebookUser, AccessToken $accessToken)
 {
     if (!$this->customer->getId()) {
         $this->customer->setEmail($facebookUser->getEmail());
         $this->customer->setFirstname($facebookUser->getFirstName());
         $this->customer->setLastname($facebookUser->getLastName());
         $this->customer->setMiddlename($facebookUser->getMiddleName());
         $this->customer->setGender((int) ($facebookUser->getGender() == 'male'));
     }
     $this->customer->setCustomAttribute('sf_id', $facebookUser->getId());
     $this->customer->setCustomAttribute('sf_access_token', serialize($accessToken));
     if ($this->customer->getId()) {
         $customer = $this->customerRepository->save($this->customer);
     } else {
         $customer = $this->accountManagement->createAccount($this->customer);
     }
     $this->login($customer->getId());
     return $customer;
 }
Ejemplo n.º 2
0
 /**
  * Build new User Model from Facebook GraphUser object
  *
  * @param GraphUser $user
  *
  * @return App\User $new
  */
 protected function validateUserData(GraphUser $user)
 {
     $new = new User();
     $new->facebook_id = $user->getId();
     $new->name = $user->getName();
     $new->avatar = $user->getPicture()->getUrl();
     $new->last_login = Carbon::now()->toDayDateTimeString();
     if (is_null($user->getEmail())) {
         $new->email = 'No Email';
     } else {
         $new->email = $user->getEmail();
     }
     if (is_null($user->getLocation())) {
         $new->location = 'No location';
     } else {
         $new->location = $user->getLocation()->getName();
     }
     return $new;
 }
Ejemplo n.º 3
0
 /**
  * Get the Facebook account registered email
  *
  * @return string
  */
 public function getEmail()
 {
     return $this->graphuser->getEmail();
 }