protected function _fetchAvatarsFromExternalSites() { /* @var $externalAuthModel XenForo_Model_UserExternal */ $externalAuthModel = $this->getModelFromCache('XenForo_Model_UserExternal'); $external = $externalAuthModel->getExternalAuthAssociationsForUser($this->get('user_id')); $fbUser = false; if (!empty($external['facebook'])) { $extra = @unserialize($external['twitter']['extra_data']); if (!empty($extra['token'])) { $avatarData = XenForo_Helper_Facebook::getUserPicture($extra['token']); if ($avatarData && $this->_applyAvatar($avatarData)) { return true; } } } $twitterUser = false; if (!empty($external['twitter'])) { $extra = @unserialize($external['twitter']['extra_data']); if (!empty($extra['token'])) { $credentials = XenForo_Helper_Twitter::getUserFromToken($extra['token'], $extra['secret']); if (!empty($credentials['profile_image_url'])) { try { // get the original size $url = str_replace('_normal', '', $credentials['profile_image_url']); $request = XenForo_Helper_Http::getClient($url)->request(); $avatarData = $request->getBody(); } catch (Exception $e) { $avatarData = ''; } if ($avatarData && $this->_applyAvatar($avatarData)) { return true; } } } } $externalExtendedHelpers = array('battlenet' => 'BattleNet', 'github' => 'GitHub', 'linkedin' => 'LinkedIn', 'live' => 'Live', 'odnoklassniki' => 'Odnoklassniki', 'soundcloud' => 'SoundCloud', 'tumblr' => 'Tumblr', 'twitch' => 'Twitch', 'vk' => 'VK'); foreach ($externalExtendedHelpers as $provider => $class) { if (!empty($external[$provider])) { $extra = $external[$provider]['extra_data']; if (!empty($extra['token'])) { $helper = $this->_getExternalExtendedHelper($class); if ($helper->avatarExists) { $eeUser = $helper->getUserInfo($extra['token']); $avatarData = $helper->getAvatar($eeUser); if ($avatarData && $this->_applyAvatar($avatarData)) { return true; } } } } } return false; }
public function actionTwitter() { $assocUserId = $this->_input->filterSingle('assoc', XenForo_Input::UINT); $oauth = XenForo_Helper_Twitter::getOauthConsumer(XenForo_Link::buildPublicLink('canonical:register/twitter', null, array('assoc' => $assocUserId ? $assocUserId : false))); if (!$oauth) { return $this->responseRedirect(XenForo_ControllerResponse_Redirect::RESOURCE_CANONICAL, $this->getDynamicRedirect()); } $session = XenForo_Application::getSession(); $redirect = $this->_getExternalAuthRedirect(); if ($this->_input->filterSingle('reg', XenForo_Input::UINT)) { XenForo_Application::getSession()->set('loginRedirect', $redirect); try { $requestToken = $oauth->getRequestToken(); } catch (Zend_Oauth_Exception $e) { return $this->responseError(new XenForo_Phrase('unexpected_error_occurred')); } $session->set('twitterRequestToken', serialize($requestToken)); return $this->responseRedirect(XenForo_ControllerResponse_Redirect::RESOURCE_CANONICAL, $oauth->getRedirectUrl()); } try { $requestToken = @unserialize($session->get('twitterRequestToken')); if ($requestToken) { if ($this->_input->filterSingle('denied', XenForo_Input::STRING)) { return $this->responseError(new XenForo_Phrase('unexpected_error_occurred')); } $accessToken = $oauth->getAccessToken($this->_input->filter(array('oauth_token' => XenForo_Input::STRING, 'oauth_verifier' => XenForo_Input::STRING)), $requestToken); } else { $accessToken = @unserialize($session->get('twitterAccessToken')); if (!$accessToken) { return $this->responseError(new XenForo_Phrase('unexpected_error_occurred')); } } } catch (Zend_Service_Twitter_Exception $e) { return $this->responseError(new XenForo_Phrase('unexpected_error_occurred')); } $session->remove('twitterRequestToken'); $session->set('twitterAccessToken', serialize($accessToken)); $credentials = XenForo_Helper_Twitter::getUserFromToken($accessToken); if (!$credentials) { return $this->responseError(new XenForo_Phrase('unexpected_error_occurred')); } $userId = $credentials['id_str']; $userModel = $this->_getUserModel(); $userExternalModel = $this->_getUserExternalModel(); $redirect = XenForo_Application::getSession()->get('loginRedirect'); $twitterAssoc = $userExternalModel->getExternalAuthAssociation('twitter', $userId); if ($twitterAssoc && $userModel->getUserById($twitterAssoc['user_id'])) { $userExternalModel->updateExternalAuthAssociationExtra($twitterAssoc['user_id'], 'twitter', array('token' => $accessToken->getToken(), 'secret' => $accessToken->getTokenSecret())); /** @var XenForo_ControllerHelper_Login $loginHelper */ $loginHelper = $this->getHelper('Login'); $loginHelper->tfaRedirectIfRequiredPublic($twitterAssoc['user_id'], $redirect, true); $visitor = XenForo_Visitor::setup($twitterAssoc['user_id']); XenForo_Application::getSession()->userLogin($twitterAssoc['user_id'], $visitor['password_date']); $this->_getUserModel()->setUserRememberCookie($twitterAssoc['user_id']); return $this->responseRedirect(XenForo_ControllerResponse_Redirect::SUCCESS, $redirect ? $redirect : $this->getDynamicRedirect(false, false)); } parent::_assertBoardActive('twitter'); $session->set('twitterCredentials', serialize($credentials)); $viewName = 'XenForo_ViewPublic_Register_Twitter'; $templateName = 'register_twitter'; $existingUser = XenForo_Visitor::getUserId() ? XenForo_Visitor::getInstance() : false; if ($existingUser) { // must associate: matching user return $this->_getExternalRegisterFormResponse($viewName, $templateName, array('associateOnly' => true, 'existingUser' => $existingUser, 'redirect' => $redirect)); } $this->_assertRegistrationActive(); return $this->_getExternalRegisterFormResponse($viewName, $templateName, array('redirect' => $redirect, 'credentials' => $credentials)); }
public function actionExtra() { $userId = $this->_input->filterSingle('user_id', XenForo_Input::UINT); $user = $this->_getUserOrError($userId); /** @var XenForo_Model_UserUpgrade $upgradeModel */ $upgradeModel = $this->getModelFromCache('XenForo_Model_UserUpgrade'); $upgradeRecords = $upgradeModel->getActiveUserUpgradeRecordsForUser($user['user_id']); /** @var XenForo_Model_UserExternal $externalAuthModel */ $externalAuthModel = $this->getModelFromCache('XenForo_Model_UserExternal'); $external = $externalAuthModel->getExternalAuthAssociationsForUser($user['user_id']); $fbUser = false; if (!empty($external['facebook'])) { $extra = @unserialize($external['facebook']['extra_data']); if (!empty($extra['token'])) { $fbUser = XenForo_Helper_Facebook::getUserInfo($extra['token'], $external['facebook']['provider_key']); } } $twitterUser = false; if (!empty($external['twitter'])) { $extra = @unserialize($external['twitter']['extra_data']); if (!empty($extra['token'])) { $twitterUser = XenForo_Helper_Twitter::getUserFromToken($extra['token'], $extra['secret']); } } return $this->responseView('XenForo_ViewAdmin_User_Extra', 'user_extra', array('user' => $user, 'upgradeRecords' => $upgradeRecords, 'external' => $external, 'fbUser' => $fbUser, 'twitterUser' => $twitterUser)); }
public function actionExternalAccounts() { $visitor = XenForo_Visitor::getInstance(); $auth = $this->_getUserModel()->getUserAuthenticationObjectByUserId($visitor['user_id']); if (!$auth) { return $this->responseNoPermission(); } /** @var XenForo_Model_UserExternal $externalAuthModel */ $externalAuthModel = $this->getModelFromCache('XenForo_Model_UserExternal'); $external = $externalAuthModel->getExternalAuthAssociationsForUser($visitor['user_id']); $fbUser = false; if (!empty($external['facebook'])) { $extra = @unserialize($external['facebook']['extra_data']); if (!empty($extra['token'])) { $fbUser = XenForo_Helper_Facebook::getUserInfo($extra['token'], $external['facebook']['provider_key']); } } $twitterUser = false; if (!empty($external['twitter'])) { $extra = @unserialize($external['twitter']['extra_data']); if (!empty($extra['token'])) { $twitterUser = XenForo_Helper_Twitter::getUserFromToken($extra['token'], $extra['secret']); } } $viewParams = array('external' => $external, 'fbUser' => $fbUser, 'twitterUser' => $twitterUser, 'hasPassword' => $auth->hasPassword()); return $this->_getWrapper('account', 'externalAccounts', $this->responseView('XenForo_ViewPublic_Account_ExternalAccounts', 'account_external_accounts', $viewParams)); }
public function actionTestTwitter() { $oauth = XenForo_Helper_Twitter::getOauthConsumer(XenForo_Link::buildAdminLink('canonical:tools/test-twitter')); if (!$oauth) { $group = $this->getModelFromCache('XenForo_Model_Option')->getOptionGroupById('twitter'); $url = XenForo_Link::buildAdminLink('options/list', $group); return $this->responseError(new XenForo_Phrase('to_test_twitter_integration_must_enter_application_info', array('url' => $url))); } $session = XenForo_Application::getSession(); if ($this->_input->filterSingle('test', XenForo_Input::UINT)) { try { $requestToken = $oauth->getRequestToken(); } catch (Exception $e) { return $this->responseError(new XenForo_Phrase('twitter_returned_following_error_x', array('error' => $e->getMessage()))); } $session->set('twitterRequestToken', serialize($requestToken)); return $this->responseRedirect(XenForo_ControllerResponse_Redirect::RESOURCE_CANONICAL, $oauth->getRedirectUrl()); } if ($this->_input->filterSingle('denied', XenForo_Input::STRING)) { return $this->responseError(new XenForo_Phrase('twitter_returned_following_error_x', array('error' => 'denied'))); } $info = false; $twitterInput = $this->_input->filter(array('oauth_token' => XenForo_Input::STRING, 'oauth_verifier' => XenForo_Input::STRING)); if ($twitterInput['oauth_token']) { $requestToken = @unserialize($session->get('twitterRequestToken')); if (!$requestToken) { return $this->responseError(new XenForo_Phrase('twitter_returned_following_error_x', array('error' => 'no_request_token'))); } try { $accessToken = $oauth->getAccessToken($twitterInput, $requestToken); } catch (Exception $e) { return $this->responseError(new XenForo_Phrase('twitter_returned_following_error_x', array('error' => $e->getMessage()))); } $session->remove('twitterRequestToken'); $info = XenForo_Helper_Twitter::getUserFromToken($accessToken, null, $e); if (!$info) { return $this->responseError(new XenForo_Phrase('twitter_returned_following_error_x', array('error' => $e ? $e->getMessage() : 'unknown'))); } } $viewParams = array('twitterInfo' => $info); return $this->responseView('XenForo_ViewAdmin_Tools_TestTwitter', 'tools_test_twitter', $viewParams); }