diff --git a/modules/boonex/okta_connect/classes/BxOktaConCustom.php b/modules/boonex/okta_connect/classes/BxOktaConCustom.php index 0da5ca673c..e3805fc160 100644 --- a/modules/boonex/okta_connect/classes/BxOktaConCustom.php +++ b/modules/boonex/okta_connect/classes/BxOktaConCustom.php @@ -19,12 +19,14 @@ function onConfig ($oConfig) { } - function onRegister ($aRemoteProfileInfo) + function onRegister ($iProfileId, $aRemoteProfileInfo) { bx_log('bx_oktacon', $aRemoteProfileInfo); if (!empty($aRemoteProfileInfo['communities'])) - $this->syncCommunities(bx_get_logged_profile_id(), explode(',', $aRemoteProfileInfo['communities'])); + $this->syncCommunities($iProfileId, explode(',', $aRemoteProfileInfo['communities'])); + + $this->syncLocation($iProfileId, $aRemoteProfileInfo); } function onLogin ($oProfile, $aRemoteProfileInfo) @@ -33,11 +35,51 @@ function onLogin ($oProfile, $aRemoteProfileInfo) if (!empty($aRemoteProfileInfo['communities'])) $this->syncCommunities($oProfile ? $oProfile->id() : bx_get_logged_profile_id(), explode(',', $aRemoteProfileInfo['communities'])); + + $this->syncLocation($oProfile->id(), $aRemoteProfileInfo); } function onConvertRemoteFields($aProfileInfo, &$aProfileFields) { + if (empty($aProfileInfo['grade'])) + return; + + $a = explode(',', $aProfileInfo['grade']); + + $v = 0; + foreach ($a as $i) { + $v += pow(2, (int)$i - 1); + } + + $aProfileFields['grades'] = $v; + } + + function syncLocation($iProfileId, $aRemoteProfileInfo) + { + if (empty($aRemoteProfileInfo['state']) || empty($aRemoteProfileInfo['city'])) + return; + + $oProfile = BxDolProfile::getInstance($iProfileId); + if (!$oProfile) + return; + + $oMetatags = BxDolMetatags::getObjectInstance('bx_persons'); + if (!$oMetatags || !$oMetatags->locationsIsEnabled()) + return; + $sEndpoint = bx_append_url_params('https://nominatim.openstreetmap.org', [ + 'format' => 'json', + 'limit' => 1, + 'country' => empty($aRemoteProfileInfo['country']) ? 'US' : $aRemoteProfileInfo['country'], + 'state' => $aRemoteProfileInfo['state'], + 'city' => $aRemoteProfileInfo['city'], + ]); + $sResults = bx_file_get_contents($sEndpoint); + if (!($a = @json_decode($sResults, true))) + return; + $a = array_shift($a); + + $oMetatags->locationsAdd($oProfile->getContentId(), $a['lat'], $a['lon'], 'US', $aRemoteProfileInfo['state'], $aRemoteProfileInfo['city']); } function syncCommunities($iProfileId, $aCommunities, $sModule = 'bx_groups', $sObjConn = 'bx_groups_fans') diff --git a/modules/boonex/okta_connect/classes/BxOktaConModule.php b/modules/boonex/okta_connect/classes/BxOktaConModule.php index 376e2bd7ca..6b0322a2af 100644 --- a/modules/boonex/okta_connect/classes/BxOktaConModule.php +++ b/modules/boonex/okta_connect/classes/BxOktaConModule.php @@ -117,21 +117,20 @@ function actionHandle() */ if ($aRemoteProfileInfo) { - bx_import('Custom', $this->_aModule); - $oCustom = new BxOktaConCustom($this->_aModule); - // check if user logged in before $iLocalProfileId = $this->_oDb->getProfileId($aRemoteProfileInfo['id']); if ($iLocalProfileId && $oProfile = BxDolProfile::getInstance($iLocalProfileId)) { // user already exists $this->setLogged($oProfile->id(), '', true, getParam('bx_oktacon_remember_session')); // remember user + bx_import('Custom', $this->_aModule); + $oCustom = new BxOktaConCustom($this->_aModule); $oCustom->onLogin($oProfile, $aRemoteProfileInfo); } else { // register new user $this->_createProfile($aRemoteProfileInfo); - $oCustom->onRegister($aRemoteProfileInfo); + } } else { @@ -139,6 +138,18 @@ function actionHandle() } } + function _createProfileRaw($aProfileInfo, $sAlternativeName = '', $isAutoFriends = true, $isSetLoggedIn = true) + { + $mixed = parent::_createProfileRaw($aProfileInfo, $sAlternativeName, $isAutoFriends, $isSetLoggedIn); + if (is_array($mixed) && isset($mixed['profile_id']) && (!isset($mixed['join_page_redirect']) || !$mixed['join_page_redirect'])) { + bx_import('Custom', $this->_aModule); + $oCustom = new BxOktaConCustom($this->_aModule); + $oCustom->onRegister($mixed['profile_id'], $aProfileInfo); + } + + return $mixed; + } + /** * @param $aProfileInfo - remote profile info * @param $sAlternativeName - suffix to add to NickName to make it unique