Przeglądaj źródła

Ticket #4971 - Build-in API support: Google Connect.

AntonLV 1 rok temu
rodzic
commit
0f6a72002d

+ 18 - 4
modules/base/connect/classes/BxBaseModConnectModule.php

@@ -59,9 +59,10 @@ class BxBaseModConnectModule extends BxBaseModGeneralModule
         bx_login($oProfile->getAccountId(), $bRememberMe);
 
         if ($bRedirect) {
-            $sCallbackUrl = $sCallbackUrl
-                ? $sCallbackUrl
-                : $this -> _oConfig -> sDefaultRedirectUrl;
+            $sCallbackUrl = $sCallbackUrl ? $sCallbackUrl : $this -> _oConfig -> sDefaultRedirectUrl;
+            
+            if($this->_bIsApi)
+                return [bx_api_get_block('redirect', ['uri' => bx_api_get_relative_url($sCallbackUrl)])];
 
             header('Location: ' . $sCallbackUrl);
         }
@@ -97,12 +98,18 @@ class BxBaseModConnectModule extends BxBaseModGeneralModule
         
         // display error
         if (is_string($mixed)) {
+            if($this->_bIsApi)
+                return [bx_api_get_msg($mixed)];
+
             $this->_oTemplate->getPage(_t($this->_oConfig->sDefaultTitleLangKey), DesignBoxContent(_t($this->_oConfig->sDefaultTitleLangKey), MsgBox($mixed)));
             exit;
         } 
 
         // display join page
         if (is_array($mixed) && isset($mixed['join_page_redirect'])) {
+            if($this->_bIsApi)
+                return []; //--- Isn't currently supported for API.
+            
             $this->_getJoinPage($mixed['profile_fields'], $mixed['remote_profile_info']['id']);
             exit;
         } 
@@ -111,11 +118,18 @@ class BxBaseModConnectModule extends BxBaseModGeneralModule
         if (is_array($mixed) && isset($mixed['profile_id'])) {
             $iProfileId = (int)$mixed['profile_id'];
 
+            $sRedirectUrl = $this->_getRedirectUrl($iProfileId, $mixed['existing_profile']);
+            if($this->_bIsApi)
+                return [bx_api_get_block('redirect', ['uri' => bx_api_get_relative_url($sRedirectUrl)])];
+
             //redirect to other page
-            header('location:' . $this->_getRedirectUrl($iProfileId, $mixed['existing_profile']));
+            header('location:' . $sRedirectUrl);
             exit;
         }
 
+        if($this->_bIsApi)
+            return [bx_api_get_msg(_t('_Error Occured'))];
+
         $this->_oTemplate->getPage( _t($this->_oConfig->sDefaultTitleLangKey), MsgBox(_t('_Error Occured')) );
         exit;
     }

+ 31 - 0
modules/boonex/google_connect/classes/BxGoogleConModule.php

@@ -118,6 +118,37 @@ class BxGoogleConModule extends BxBaseModConnectModule
         }
     }
 
+    public function serviceGetSafeServices()
+    {
+        return array_merge(parent::serviceGetSafeServices(), [
+            'Handle' => '',
+        ]);
+    }
+
+    public function serviceHandle($aRemoteProfileInfo = [])
+    {
+        if(!$this->_bIsApi)
+            return;
+
+        if(is_string($aRemoteProfileInfo))
+            $aRemoteProfileInfo = bx_api_get_browse_params($aRemoteProfileInfo);
+
+        if(empty($aRemoteProfileInfo) || !is_array($aRemoteProfileInfo))
+            return [
+                bx_api_get_msg(_t('_sys_connect_profile_error_info'))
+            ];
+
+        if(empty($aRemoteProfileInfo['id']) && !empty($aRemoteProfileInfo['sub']))
+            $aRemoteProfileInfo['id'] = $aRemoteProfileInfo['sub'];
+        
+        // check if user logged in before
+        $iProfileId = $this->_oDb->getProfileId($aRemoteProfileInfo['id']);
+        if($iProfileId && $oProfile = BxDolProfile::getInstance($iProfileId))
+            return $this->setLogged($oProfile->id());
+        else
+            return $this->_createProfile($aRemoteProfileInfo);
+    }
+
     /**
      * @param $aProfileInfo - remote profile info
      * @param $sAlternativeName - suffix to add to NickName to make it unique