예제 #1
0
 /**
  * _displayAccount() method displays fancybox if customer do not use a social connector to link his PS account
  *
  * @category hook collection
  * @uses
  *
  * @param array $aParams
  * @return array
  */
 private function _displayAccount()
 {
     $aAssign = array('iCustomerId' => $this->iCustomerLogged, 'bUseJqueryUI' => true);
     $aAssign['bDisplay'] = false;
     // if one of connectors is active at least
     if (self::$bConnectorsActive) {
         require_once _FPC_PATH_LIB . 'module-dao_class.php';
         // include abstract connector
         require_once _FPC_PATH_LIB_CONNECTOR . 'base-connector_class.php';
         if (FacebookPsConnect::$aConfiguration[_FPC_MODULE_NAME . '_DISPLAY_FB_POPIN'] && !empty($GLOBALS[_FPC_MODULE_NAME . '_CONNECTORS']['facebook']['data']['activeConnector'])) {
             // set
             $bSocialCustomerExist = false;
             // loop on each connector to check if social account already exists - if not, display FB popin account association
             foreach ($GLOBALS[_FPC_MODULE_NAME . '_CONNECTORS'] as $sName => $aConnector) {
                 if (!empty($GLOBALS[_FPC_MODULE_NAME . '_CONNECTORS'][$sName]['data'])) {
                     // get connector options
                     $aParams = $GLOBALS[_FPC_MODULE_NAME . '_CONNECTORS'][$sName]['data'];
                     // get connector
                     $oConnector = BT_BaseConnector::get($sName, $aParams);
                     // check if customer is already logged from FB connector
                     if ($oConnector->existSocialAccount($aAssign['iCustomerId'], 'ps')) {
                         $bSocialCustomerExist = true;
                     }
                     unset($oConnector);
                 }
             }
             if (!BT_FPCModuleDao::existCustomerAssociationStatus(FacebookPsConnect::$iShopId, $this->iCustomerLogged) && empty($bSocialCustomerExist)) {
                 $aAssign['bDisplay'] = true;
                 $aAssign['bSocialCustomerExist'] = true;
                 $aAssign['sConnectorButtonFacebook'] = BT_FPCModuleTools::getTemplatePath(_FPC_PATH_TPL_NAME . _FPC_TPL_HOOK_PATH . _FPC_TPL_BUTTON_FB);
                 $aAssign['sModuleURI'] = $this->sModuleURI;
                 $aAssign['bFriendlyPermission'] = $GLOBALS[_FPC_MODULE_NAME . '_CONNECTORS']['facebook']['data']['permissions'];
                 $aAssign['sBackUri'] = self::$sCurrentURI;
             }
         }
         // get connector options
         $aParams = $GLOBALS[_FPC_MODULE_NAME . '_CONNECTORS']['twitter']['data'];
         // test if twitter is already configured
         if (!empty($aParams)) {
             // get connector
             $oConnector = BT_BaseConnector::get('twitter', $aParams);
             // check if customer is already logged from FB connector
             if ($oConnector->existSocialAccount($aAssign['iCustomerId'], 'ps') && strstr(FacebookPsConnect::$oCookie->email, 'twitter.com')) {
                 $aAssign['iCustomerId'] = md5(_FPC_MODULE_NAME . 'twitter' . $aAssign['iCustomerId']);
                 $aAssign['sConnector'] = 'twitter';
                 $aAssign['bTwitterCustomerExist'] = true;
                 $aAssign['bDisplay'] = true;
             }
             unset($oConnector);
         }
         // use case - data sent for collecting
         $sRequestData = Tools::getValue('data');
         if (!empty($sRequestData)) {
             $aRequestData = unserialize(gzuncompress(urldecode(base64_decode($sRequestData))));
             if (!empty($aRequestData)) {
                 if (empty($aRequestData['ci'])) {
                     $aRequestData['ci'] = md5('collect' . FacebookPsConnect::$oCookie->id_customer);
                     if (!empty($aRequestData['cn']) && !empty($aRequestData['ca']) && !empty($aRequestData['ct']) && !empty($aRequestData['oi'])) {
                         // execute social collect method
                         $sReturn = FacebookPsConnect::$oModule->HookSocialCollector(base64_decode($aRequestData['cn']), $aRequestData);
                         if (!empty($sReturn)) {
                             // get collect data array
                             $oResponse = BT_FPCModuleTools::jsonDecode($sReturn);
                             if (!empty($oResponse->status)) {
                                 $aAssign['bCustomerCollect'] = true;
                             }
                         }
                     }
                 }
             }
         }
     }
     $aAssign['sModuleURI'] = _FPC_MODULE_URL . 'ws-' . _FPC_MODULE_SET_NAME . '.php';
     return array('tpl' => _FPC_TPL_HOOK_PATH . _FPC_TPL_CONNECTOR_ACCOUNT, 'assign' => $aAssign);
 }
 /**
  * connect() method check if token is valid or not, and either redirect on FB interface or log the customer by creating his account if necessary
  *
  * @param array $aParams
  * @return string
  */
 public function connect(array $aParams = null)
 {
     // use case - not FB code returned - redirect
     if (empty($aParams['code']) || empty($aParams['access_token'])) {
         // redirect on FB interface
         $this->redirect();
     } else {
         // test token
         // $oFBUser = BT_FPCModuleTools::jsonDecode(BT_FPCModuleTools::fileGetContent('https://graph.facebook.com/me?access_token=' . $aParams['access_token']));
         $oFBUser = BT_FPCModuleTools::jsonDecode(BT_FPCModuleTools::fileGetContent('https://graph.facebook.com/me?fields=id,name,last_name,first_name,email&access_token=' . $aParams['access_token']));
         // only if social user id exist
         if (!empty($oFBUser->id)) {
             // set create status
             $bCreateStatus = true;
             $bCreatePs = false;
             $bCreateSocial = false;
             // set FB data
             $this->oUser->id = $oFBUser->id;
             $this->oUser->customerId = 0;
             $this->oUser->first_name = $oFBUser->first_name;
             $this->oUser->last_name = $oFBUser->last_name;
             $this->oUser->email = $oFBUser->email;
             // set birthday
             if (!empty($oFBUser->birthday)) {
                 $aBirthday = explode('/', $oFBUser->birthday);
                 // format date for PS customer table
                 $this->oUser->birthday = $aBirthday[2] . '-' . $aBirthday[0] . '-' . $aBirthday[1];
             }
             // set gender
             if (!empty($oFBUser->gender)) {
                 // get gender ID from PS
                 $this->oUser->gender = parent::getGender($oFBUser->gender);
             }
             // use case - customer is already logged and ask him account association
             if (($iCustomerId = self::$oSession->get('iCustomerId')) !== null) {
                 // get customer id
                 $this->oUser->customerId = $iCustomerId;
                 // delete customer ID session
                 self::$oSession->delete('iCustomerId');
                 // use case - social account not exists
                 if (!parent::existSocialAccount($this->oUser->id)) {
                     $bCreateSocial = true;
                 } else {
                     $aSocialData = parent::getSocialData($oFBUser->id);
                     // get customer data of old account
                     $aCustomerData = parent::getCustomerData($aSocialData[0]['CNT_CUST_ID']);
                     throw new BT_FacebookException(FacebookPsConnect::$oModule->l('This Facebook account has already been linked to a customer account on our shop. The e-mail address of this account on our shop is', 'facebook-connector_class') . ' : "' . $aCustomerData[0]['email'] . '". ' . FacebookPsConnect::$oModule->l('Please contact the merchant to warn him', 'facebook-connector_class') . '.', 520);
                 }
             } else {
                 // test if user already exist in social table
                 $bCreateSocial = !parent::existSocialAccount($this->oUser->id);
                 // test if user already exist in PS table
                 $bCreatePs = !parent::existPsAccount($this->oUser->email);
                 // use case - social account exist
                 if (empty($bCreateSocial)) {
                     // use case - create new PS account and have to delete old social account
                     if (!empty($bCreatePs)) {
                         $iCustomerId = parent::getCustomerId($this->oUser->id);
                         // use case - PS customer account exists too
                         if (parent::existPsAccount($iCustomerId, 'id')) {
                             $bCreateSocial = false;
                             $bCreatePs = false;
                         } else {
                             parent::deleteSocialAccount($this->oUser->id);
                             $bCreateSocial = true;
                         }
                     }
                 } elseif (!$bCreatePs) {
                     $this->oUser->customerId = parent::getCustomerIdByMail($this->oUser->email);
                 }
             }
             // use case - if one of 2 accounts has to be created at least
             if (!empty($bCreatePs) || !empty($bCreateSocial)) {
                 // create customer in 1 or 2 tables
                 $bCreateStatus = parent::createCustomer($bCreatePs, $bCreateSocial);
             }
             // use case  - create status valid
             if ($bCreateStatus) {
                 // load customer
                 parent::loadCustomer($this->oUser->id);
                 // get data session if exists
                 $sData = self::$oSession->get('data');
                 // delete session
                 self::$oSession->delete('data');
                 return $this->login($sData);
             } else {
                 throw new BT_FacebookException(FacebookPsConnect::$oModule->l('Internal server error. Account creation processing is unavailable', 'facebook-connector_class'), 521);
             }
         } else {
             throw new BT_FacebookException(FacebookPsConnect::$oModule->l('The token is not valid. You may be a victim of cross-site request forgery or the connect method to the Facebook URL with HTTPS is not allowed. Please contact the merchant to warn him', 'facebook-connector_class'), 522);
         }
     }
 }
 /**
  * getProfile() method returns the customer's profile
  *
  *
  * @param array $aToken
  * @return array
  */
 public function getProfile(array $aToken)
 {
     $sProfileUrl = sprintf("%s?schema=openid&access_token=%s", "https://api.paypal.com/v1/identity/openidconnect/userinfo/", $aToken['access_token']);
     return BT_FPCModuleTools::jsonDecode($this->runCurl($sProfileUrl));
 }