Ejemplo n.º 1
0
 public function Set($params)
 {
     $this->_current_url_no_lacate = \Av\UrlControllerHelper::BuildUrl($params);
     $params[self::COUNTRY_ID] = \Av\Localization\LocalizationController::GetLocale()->GetCountryId();
     $params[self::LANGUAGE_ID] = \Av\Localization\LocalizationController::GetLocale()->GetLanguageId();
     $this->_current_url = \Av\UrlControllerHelper::BuildUrl($params);
 }
Ejemplo n.º 2
0
 /**
  * Generic function to build Google services authorizationUrl base on Google Service Id ( see table "media")<br>
  * and Authorization Type Id ( see tabel "media_auth_type" )<br>
  * @param array $params[self::MEDIA_ID] AND $params[self::AUTH_TYPE_ID]
  * @return array $arrMediaAuthLinks['media_links'][<Media Display Name>][<Media Authorization Url] 
  * @throws \Exception If are not set $params[self::MEDIA_ID]  || $params[self::AUTH_TYPE_ID]
  */
 protected function GoogelAction($params)
 {
     // 1. Check if GOOGLE service signup authorization is active
     $arrMediaAuthLinks = array();
     $oMediaAuthMap = new \Av\MediaAuthTypeMapModel();
     $GOOGLE_MEDIA_ID = isset($params[self::MEDIA_ID]) ? $params[self::MEDIA_ID] : null;
     $GOOGLE_AUTH_TYPE_ID = isset($params[self::AUTH_TYPE_ID]) ? $params[self::AUTH_TYPE_ID] : null;
     //        $this->AddDebug(__METHOD__ . " #" . __LINE__ .  " \n  params are:  \n" . print_r($params,true) );
     if (empty($GOOGLE_MEDIA_ID)) {
         throw new \Exception("GOOGLE Media id is missing or invalid");
     }
     if (empty($GOOGLE_AUTH_TYPE_ID)) {
         throw new \Exception("GOOGLE auth type is missing or invalid");
     }
     //         $this->AddDebug(__METHOD__ . " #" . __LINE__ .  " \n  no exeptions\n" . print_r($params,true) );
     // 1.1 What media(s) choices do we have for the authorization?
     //     Authorization type may be SignUp, SignIn ..... See table "media_auth_type"
     $arrActiveSignUpMedia = $oMediaAuthMap->GetMediaAuthMap(array(\Av\MediaAuthTypeMapModel::MEDIA_ID => $GOOGLE_MEDIA_ID, \Av\MediaAuthTypeMapModel::STATUS => \Av\MediaAuthTypeMapModel::STATUS_ACTIVE, \Av\MediaAuthTypeMapModel::AUTH_TYPE_ID => $GOOGLE_AUTH_TYPE_ID));
     //        $this->AddDebug(__METHOD__ . " #" . __LINE__ .  " \n #1 ActiveSignUpMedia:  \n" . print_r($arrActiveSignUpMedia,true) );
     if (isset($arrActiveSignUpMedia[$GOOGLE_AUTH_TYPE_ID])) {
         $arrActiveSignUpMedia = $arrActiveSignUpMedia[$GOOGLE_AUTH_TYPE_ID];
         //            $this->AddDebug(__METHOD__ . " #" . __LINE__ .  " \n #2 ActiveSignUpMedia:  \n" . print_r($arrActiveSignUpMedia,true) );
         $oMediaModel = new \Av\MediaModel();
         foreach ($arrActiveSignUpMedia as $currentMedia) {
             $params_media_info = array(\Av\MediaModel::MEDIA_ID => $currentMedia[\Av\MediaAuthTypeMapModel::MEDIA_ID]);
             $media_info = $oMediaModel->GetMediaInfo($params_media_info);
             //                $this->AddDebug(__METHOD__ . " #" . __LINE__ .  " \n media info:" . print_r($media_info,true) . "\n params are:" . print_r($params_media_info, true) . "\n");
             if (isset($media_info[\Av\MediaModel::MEDIA_NAME])) {
                 $state = \Av\UrlControllerHelper::packParamForUrl(array(\Av\Acl\RoleModel::ROLE_ID => \Av\Acl\RoleModel::ROLE_CLIENT_INT, \Av\MediaModel::MEDIA_ID => $currentMedia[\Av\MediaAuthTypeMapModel::MEDIA_ID]));
                 //                    $this->AddDebug(__METHOD__ . " #" . __LINE__ .  " \ packed state:  \n" . print_r($state, true));
                 $arrMediaAuthLinks['media_links'][$media_info[\Av\MediaModel::MEDIA_NAME]] = $this->LoginURL(array(self::STATE => $state, self::AUTH_TYPE_ID => $currentMedia[\Av\MediaAuthTypeMapModel::AUTH_TYPE_ID], self::MEDIA_ID => $currentMedia[\Av\MediaAuthTypeMapModel::MEDIA_ID]));
             }
         }
     }
     return empty($arrMediaAuthLinks) ? false : $arrMediaAuthLinks;
 }
 public function GetAuthResponse($params)
 {
     if (isset($params[self::CODE]) && $params[self::CODE] != 400) {
         $this->AddDebug(__METHOD__ . " #" . __LINE__ . " response :" . print_r($params, true));
         //	    echo __METHOD__ . __LINE__ .  self " user id {$usr_id} /  CODE {$params['code']} user brands <br> are: <br><pre>"; var_dump($oauth); echo "</pre>";
         $CODE = $params[self::CODE];
         $STATE = isset($params[self::STATE]) ? \Av\UrlControllerHelper::unpackParamFromUrl($params[self::STATE]) : null;
         $GOOGLE_MEDIA_ID = isset($STATE[self::MEDIA_ID]) ? $STATE[self::MEDIA_ID] : null;
         if (!isset($GOOGLE_MEDIA_ID)) {
             throw new \Google_Exception("Got invalid Google Media Id from 'state'");
         }
         // 1. Get Google media id ( youtube,calendar,G+...) from state
         /*
          * Get Application credentials: client id / client secret
          */
         $oMediaClients = new \Av\ClientCredentialsModel();
         $params_credentials = array(\Av\ClientCredentialsModel::MEDIA_ID => $GOOGLE_MEDIA_ID);
         $credential = $oMediaClients->GetCredentials($params_credentials);
         $CLIENT_ID = isset($credential[\Av\ClientCredentialsModel::CLIENT_ID]) ? $credential[\Av\ClientCredentialsModel::CLIENT_ID] : null;
         $CLIENT_SECRET = isset($credential[\Av\ClientCredentialsModel::CLIENT_SECRET]) ? $credential[\Av\ClientCredentialsModel::CLIENT_SECRET] : null;
         if (!isset($CLIENT_ID) || !isset($CLIENT_SECRET)) {
             throw new \Google_Exception('You must fill out the CLIENT credentials');
         }
         /*
          * Get callback end point
          */
         $oCallBackUrl = new \Av\MediaAuthCallbackUrlModel();
         $params_callback_url = array(\Av\MediaAuthCallbackUrlModel::MEDIA_ID => $GOOGLE_MEDIA_ID, \Av\MediaAuthCallbackUrlModel::AUTH_TYPE_ID => \Av\MediaAuthTypeModel::AUTH_TYPE_SIGNUP);
         $CALBACK_URL = $oCallBackUrl->GetMediaAuthCallbackUrl($params_callback_url);
         if ($CALBACK_URL === false) {
             throw new \Google_Exception("Callback Url for media FACEBOOK and Authorization type Signup is not set");
         }
         $client = new \Google_Client();
         $client->setClientId($CLIENT_ID);
         $client->setClientSecret($CLIENT_SECRET);
         $client->setRedirectUri($CALBACK_URL);
         //	$client->setScopes(self::getScope());
         //	$client->setAccessType(self::getAccessTypeOffline());
         $client->authenticate($CODE);
         $access_token = $client->getAccessToken();
         $token = json_decode($access_token);
         $this->service_auth->SetToken($access_token);
         if (isset($token->{\Av\MediaUserModel::REFRESH_TOKEN})) {
             $this->service_auth->SetRefreshToken($token->{\Av\MediaUserModel::REFRESH_TOKEN});
         }
         if (isset($STATE)) {
             $this->service_auth->SetState($STATE);
         }
         if (!isset($GOOGLE_MEDIA_ID)) {
             throw new \Google_Exception("Got invalid GOOGLE MEDIA ID from 'state'");
         }
         // Only G+ provides peron's information
         if ($GOOGLE_MEDIA_ID == \Av\MediaModel::MEDIA_GOOGLE_PLUS) {
             $params_access_token = array(self::AUTH_TOKEN => $access_token);
             $this->service_person->MeAction($params_access_token);
         }
         $this->AddDebug(__METHOD__ . " #" . __LINE__ . " access token :" . print_r($access_token, true));
         //		 echo __METHOD__ . __LINE__ .   " access token saved with status {$ok} <br><pre>"; var_dump($access_token); echo "</pre>";
         //	    $access_token   =   $oAuthObj->authorizeToken($cDB, $code, $cAuth->szURL);
         //	    $oAuthObj->saveAuthorization($cDB, $access_token, $cAuth->szURL);
     } else {
         if (isset($params['error'])) {
             $statusMessage = "Authorization Error. ";
             $statusMessage .= $EEEOR_DELIMITER . $_GET['error'];
             $statusMessage .= $EEEOR_DELIMITER . $_GET['error_reason'];
             $statusMessage .= $EEEOR_DELIMITER . $_GET['error_description'];
             $this->AddDebug(__METHOD__ . " #" . __LINE__ . " error:" . print_r($statusMessage, true));
             //	    echo __METHOD__ . " #" .__LINE__ .   " heartsoul brand authorization error <br><pre>"; var_dump($statusMessage); echo "</pre>";
         } else {
             if ($params['code'] == 400) {
                 $statusMessage = "Authorization Error 400. ";
                 $statusMessage = $EEEOR_DELIMITER . $_GET['code'];
                 $statusMessage = $EEEOR_DELIMITER . $_GET['error_type'];
                 $statusMessage = $EEEOR_DELIMITER . $_GET['error_message'];
                 $this->AddDebug(__METHOD__ . " #" . __LINE__ . " bad code :" . print_r($statusMessage, true));
                 //	    echo __METHOD__ . " #" . __LINE__ .   " heartsoul brand authorization error <br><pre>"; var_dump($statusMessage); echo "</pre>";
             }
         }
     }
 }
 public function GetAuthResponse($params)
 {
     if (isset($params[self::CODE]) && $params[self::CODE] != 400) {
         //	     echo __METHOD__ . __LINE__ .   " user id {$usr_id} /  CODE {$params['code']} user brands <br>";
         $STATE = isset($params[self::STATE]) ? $params[self::STATE] : null;
         /*
          * Get Application credentials: client id / client secret
          */
         $oMediaClients = new \Av\ClientCredentialsModel();
         $params_credentials = array(\Av\ClientCredentialsModel::MEDIA_ID => \Av\MediaModel::MEDIA_FACEBOOK);
         $credential = $oMediaClients->GetCredentials($params_credentials);
         $APP_ID = isset($credential[\Av\ClientCredentialsModel::CLIENT_ID]) ? $credential[\Av\ClientCredentialsModel::CLIENT_ID] : null;
         $APP_SECRET = isset($credential[\Av\ClientCredentialsModel::CLIENT_SECRET]) ? $credential[\Av\ClientCredentialsModel::CLIENT_SECRET] : null;
         if (!isset($APP_ID) || !isset($APP_SECRET)) {
             throw new FacebookSDKException('You must fill out the CLIENT credentials');
         }
         FacebookSession::setDefaultApplication($APP_ID, $APP_SECRET);
         require_once 'Facebook/FacebookRedirectLoginHelper.php';
         /*
          * Get callback end point
          */
         $oCallBackUrl = new \Av\MediaAuthCallbackUrlModel();
         $params_callback_url = array(\Av\MediaAuthCallbackUrlModel::MEDIA_ID => \Av\MediaModel::MEDIA_FACEBOOK, \Av\MediaAuthCallbackUrlModel::AUTH_TYPE_ID => \Av\MediaAuthTypeModel::AUTH_TYPE_SIGNUP);
         $callback_url = $oCallBackUrl->GetMediaAuthCallbackUrl($params_callback_url);
         if ($callback_url === false) {
             throw new FacebookSDKException("Callback Url for media FACEBOOK and Authorization type Signup is not set");
         }
         $helper = new FacebookRedirectLoginHelper($callback_url);
         try {
             $session = $helper->getSessionFromRedirect();
             $ACCESS_TOKEN = $session->getToken();
             $this->service_auth->SetToken($ACCESS_TOKEN);
             if (isset($params[self::STATE])) {
                 $arrState = \Av\UrlControllerHelper::unpackParamFromUrl($params[self::STATE]);
                 $this->service_auth->SetState($arrState);
             }
         } catch (FacebookRequestException $ex) {
             echo __METHOD__ . __LINE__ . " Facebook  Authentication error <br><pre>";
             var_dump($ex);
             echo "</pre>";
             return;
         } catch (\Exception $ex) {
             echo __METHOD__ . __LINE__ . " Facebook  error during authentication <br><pre>";
             var_dump($ex);
             echo "</pre>";
             return;
         }
         $params_access_token = array(self::AUTH_TOKEN => $ACCESS_TOKEN);
         try {
             $this->service_person->MeAction($params_access_token);
         } catch (FacebookRequestException $e) {
             echo __METHOD__ . __LINE__ . " Facebook  error during getting person info <br><pre>";
             var_dump($e);
             echo "</pre>";
             return;
         }
         // get granted permissions
         try {
             $this->service_person->PermissionsAction($params_access_token);
         } catch (FacebookRequestException $e) {
             echo __METHOD__ . __LINE__ . " Facebook  error during getting permissions <br><pre>";
             var_dump($e);
             echo "</pre>";
             return;
         }
     } else {
         echo __METHOD__ . __LINE__ . " Facebook CODE is not set or set to 400<br>";
     }
 }
Ejemplo n.º 5
0
 /**
  * Returms url location for IN "map". "map=0,0" - returns contemt of all menus + front page.
  * @param array $params
  * @return array - list of menus url
  */
 public function GetMapLoc($params = null)
 {
     $arrSiteMap = array();
     if (isset($params[self::MAP_PARAM])) {
         if ($params[self::MAP_PARAM] === "0,0") {
             /**
              * Get Home Page url
              */
             $arrSiteMap[] = \RouterSettings::GetBaseUrl();
             /**
              * Read all menu.
              */
             $oMenuLoader = new MenuController();
             $currentLocale = \Av\Localization\LocalizationController::GetCurrentLocale();
             if ($currentLocale !== false) {
                 $oAllMenus = $oMenuLoader->LoadMenu(array(\Av\Component\Menu\iMenuModelInterface::LOCALE => $currentLocale));
                 //                    $this->AddDebug(__METHOD__ . " #" . __LINE__ ." all menues" .print_r($oAllMenus,true));
                 foreach ($oAllMenus->GetCollection() as $x_y_arrMenu) {
                     foreach ($x_y_arrMenu as $y_arrMenu) {
                         foreach ($y_arrMenu as $oMenu) {
                             if ($oMenu instanceof \Av\Component\Menu\MenuContainer) {
                                 //                                    $this->AddDebug(__METHOD__ . " #" . __LINE__ ." oMenu" .print_r($oMenu,true));
                                 $oResLink = $oMenu->GetMenuResLink();
                                 //                                    $this->AddDebug(__METHOD__ . " #" . __LINE__ ." ResLink" .print_r($oResLink,true));
                                 if ($oResLink instanceof \Av\Res\ResContainer) {
                                     /** 
                                      * check if it is absolute path - if not then add "base url"
                                      */
                                     $this->AddDebug(__METHOD__ . " #" . __LINE__ . " Directory Separator:" . print_r(DIRECTORY_SEPARATOR, true));
                                     $arrSiteMap[] = \Av\UrlControllerHelper::AsAbsoluteUrl($oResLink->GetMenuResValue());
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     return $arrSiteMap;
 }