コード例 #1
0
 public function init()
 {
     $this->cleanSessionData(self::NETWORK_ID);
     $GLOBALS[self::SOCIAL_ACCESS_ERROR] = array();
     if (is_null(self::$object) && empty($_SESSION['sn']['authorized'])) {
         try {
             /**
              * initialize user by profile social id
              * if not initialized trying to authorized by default
              */
             if (!empty($_SESSION[self::NETWORK_ID]['id']) && !isset($_GET['setid'])) {
                 if ($this->initializeByProfileSocialID($_SESSION[self::NETWORK_ID]['id'])) {
                     $this->flagSocialPluginInSession(self::NETWORK_ID);
                     $_SESSION[self::NETWORK_ID]['id'] = (string) self::$oProfile->id;
                     return true;
                 }
             }
             $this->saveUserGroupIDIfPossible();
             self::$object = new SJB_LinkedIn($this->createCallbackUrl());
             // check for response from LinkedIn
             if (!$this->isTokenRequested()) {
                 self::$object->_getRequestToken();
             } else {
                 if (SJB_Request::getVar(SJB_LinkedIn::OAUTH_PROBLEM)) {
                     throw new Exception('oAuth Problem: ' . SJB_Request::getVar(SJB_LinkedIn::OAUTH_PROBLEM));
                 }
                 self::$object->_getAccessToken();
                 $this->flagSocialPluginInSession(self::NETWORK_ID);
                 $this->takeDataFromServer = true;
                 $this->getProfileInformation();
                 $this->saveProfileSystemInfo();
                 // if user already registered we should link his profile with linkedIn id
                 if ($oCurrentUser = SJB_UserManager::getCurrentUser()) {
                     $this->setUserSocialIDByUserSID($oCurrentUser->getSID(), self::$oProfile->id);
                     SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/my-account/');
                 } elseif (!parent::ifUserIsRegistered(self::NETWORK_ID, null)) {
                     $this->redirectToRegistrationSocialPage();
                 }
             }
         } catch (Exception $e) {
             $this->registerError($e);
             SJB_Error::writeToLog($e->getMessage());
         }
     } elseif (self::$oProfile && !parent::ifUserIsRegistered(self::NETWORK_ID)) {
         /**
          * if user already logged in using social plugin but not registered
          * redirect him to registration social page
          */
         $this->redirectToRegistrationSocialPage();
     }
 }
コード例 #2
0
 /**
  * @param $callbackUrl
  * @param null $accessToken
  * @return SimpleXMLElement
  * @throws Exception
  */
 public function authorize($callbackUrl, $accessToken = null)
 {
     self::$object = new SJB_LinkedIn($callbackUrl);
     if (empty($accessToken)) {
         // check for response from LinkedIn
         if (!$this->isTokenRequested()) {
             self::$object->_getRequestToken();
         } else {
             if (SJB_Request::getVar(SJB_LinkedIn::OAUTH_PROBLEM)) {
                 throw new Exception('oAuth Problem: ' . SJB_Request::getVar(SJB_LinkedIn::OAUTH_PROBLEM));
             }
         }
     }
     self::$object->_getAccessToken($accessToken);
     $response = self::$object->getProfileInfo(array('id', 'email-address'));
     return new SimpleXMLElement($response);
 }