/** * Process login with Facebook * * @param \Facebook\GraphNodes\GraphUser $userNode * @return array */ private function _process($userNode) { $userInfo = []; $userInfo['email'] = $userNode->getField('email'); $userInfo['first_name'] = $userNode->getFirstName(); $userInfo['last_name'] = $userNode->getLastName(); $userInfo['facebook_id'] = $userNode->getId(); return (new ZSocialHelper($userInfo, 'facebook'))->process(); }
/** * 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; }
/** * 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; }
/** * Get the Facebook account unique id * * @return int */ public function getId() { return $this->graphuser->getId(); }