Ejemplo n.º 1
0
 /**
  * Get facebook user
  *
  * @return array|null
  */
 public function getFacebookUser()
 {
     $facebookUser = null;
     $customer = $this->customerSession->getCustomerData();
     $accessTokenAttribute = $customer->getCustomAttribute('sf_access_token');
     if ($accessTokenAttribute) {
         /** @var $accessToken \Facebook\Authentication\AccessToken */
         $accessToken = unserialize($accessTokenAttribute->getValue());
         try {
             $facebookUser = $this->facebook->get('/me?fields=' . static::FIELDS, $accessToken)->getGraphUser()->all();
         } catch (FacebookSDKException $e) {
             $this->logger->addError($e->getMessage());
         } catch (\Exception $e) {
             $this->logger->addError($e->getMessage());
         }
     }
     return $facebookUser;
 }
Ejemplo n.º 2
0
 /**
  * Dispatch request
  *
  * @return ResponseInterface
  */
 public function execute()
 {
     $facebookHelper = $this->facebook->getRedirectLoginHelper();
     try {
         $accessToken = $facebookHelper->getAccessToken();
         if (isset($accessToken)) {
             $facebookUser = $this->facebook->get('/me?fields=' . static::FIELDS, $accessToken)->getGraphUser();
             $customer = $this->customerRepository->getByFacebookId($facebookUser->getId());
             if ($this->customerSession->getId()) {
                 $this->customer = $this->customerSession->getCustomerData();
                 $this->createOrUpdateAndLogin($facebookUser, $accessToken);
                 $this->messageManager->addSuccess(__("Your Facebook account is now connected to your account at our store."));
             } else {
                 if (!is_null($customer)) {
                     $this->customer = $customer;
                     $this->createOrUpdateAndLogin($facebookUser, $accessToken);
                     $this->messageManager->addSuccess(__("You have successfully logged in using your Facebook account."));
                 } else {
                     try {
                         $this->customer = $this->customerRepository->get($facebookUser->getEmail());
                     } finally {
                         $customer = $this->createOrUpdateAndLogin($facebookUser, $accessToken);
                         if ($this->customer->getId() == $customer->getId()) {
                             $this->messageManager->addSuccess(__("We have discovered you already have an account at our store." . " Your Facebook account is now connected to your store account."));
                         } else {
                             $this->messageManager->addSuccess(__("Your Facebook account is now connected to your new user account at our store."));
                         }
                     }
                 }
             }
         } else {
             throw new FacebookSDKException('The Facebook code is null');
         }
     } catch (FacebookSDKException $e) {
         $this->logger->addError($e->getMessage());
         $this->messageManager->addError(__("Oops. Something went wrong! Please try again later."));
     } catch (InputException $e) {
         $this->logger->addError($e->getMessage());
         $this->messageManager->addError(__("Some of required values is not received. Please, check your Facebook settings." . "Required fields: email, first name, last name."));
     } catch (Exception $e) {
         $this->logger->addError($e->getMessage());
         $this->messageManager->addError(__("Oops. Something went wrong! Please try again later."));
     }
     $this->_redirect($this->_redirect->getRefererUrl());
 }
Ejemplo n.º 3
0
 /**
  * Dispatch request
  *
  * @return ResponseInterface
  */
 public function execute()
 {
     $customer = $this->customerSession->getCustomerData();
     $accessTokenAttribute = $customer->getCustomAttribute('sf_access_token');
     $facebookUserIdAttribute = $customer->getCustomAttribute('sf_access_token');
     if ($accessTokenAttribute && $facebookUserIdAttribute) {
         /** @var $accessToken \Facebook\Authentication\AccessToken */
         $accessToken = unserialize($accessTokenAttribute->getValue());
         $facebookUserId = $facebookUserIdAttribute->getValue();
         try {
             $this->facebook->delete('/' . $facebookUserId . '/permissions', [], $accessToken);
             $customer->setCustomAttribute('sf_id', null);
             $customer->setCustomAttribute('sf_access_token', null);
             $this->customerRepository->save($customer);
             $this->messageManager->addSuccess(__('You have successfully disconnected your Facebook account from our store account.'));
         } catch (Exception $e) {
             $this->logger->addError($e->getMessage());
             $this->messageManager->addError(__("Oops. Something went wrong! Please try again later."));
         }
     }
     return $this->_redirect($this->_redirect->getRefererUrl());
 }