Esempio n. 1
0
 function display($tpl = null)
 {
     $actionModel = $this->getModel('OpenGraphAction', 'JFBConnectModel');
     $activityModel = $this->getModel('OpenGraphActivity', 'JFBConnectModel');
     $objectModel = $this->getModel('OpenGraphObject', 'JFBConnectModel');
     $user = JFactory::getUser();
     if ($this->getLayout() == 'activity') {
         $activityModel->setUserId($user->get('id'));
         $rows = $activityModel->getActivityForUser();
         $this->rows = $rows;
         $this->actionModel = $actionModel;
         $this->objectModel = $objectModel;
         $pagination = $activityModel->getPagination();
         $this->pagination = $pagination;
     } else {
         if ($this->getLayout() == 'settings') {
             $user = JFactory::getUser();
             $userModel = JFBConnectModelUserMap::getUser($user->get('id'), 'facebook');
             $userData = $userModel->getData();
             $actionsDisabled = $userData->params->get('og_actions_disabled');
             $this->actionsDisabled = $actionsDisabled;
             $actionModel = $this->getModel('OpenGraphAction', 'JFBConnectModel');
             $actions = $actionModel->getActions(true);
             $editableActions = array();
             foreach ($actions as $action) {
                 if ($action->can_disable) {
                     $editableActions[] = $action;
                 }
             }
             $this->actions = $editableActions;
         }
     }
     JFBCFactory::addStylesheet('jfbconnect.css');
     parent::display($tpl);
 }
Esempio n. 2
0
 function display($tpl = null)
 {
     $user = JFactory::getUser();
     $providers = JFBCFactory::getAllProviders();
     $providerData = array();
     foreach ($providers as $provider) {
         if ($provider->appId && $provider->secretKey) {
             $userModel = JFBConnectModelUserMap::getUser($user->get('id'), $provider->systemName);
             $userData = $userModel->getData();
             $providerInfo = new stdClass();
             $providerInfo->profileUrl = $userData->params->get('data.profile_url');
             if (empty($providerInfo->profileUrl)) {
                 //JOOMLA 2.5
                 $providerInfo->profileUrl = $userData->params->get('profile_url');
             }
             $providerInfo->isMapped = $userData->provider != null;
             $providerInfo->name = $provider->name;
             $providerInfo->provider = $provider;
             $providerInfo->systemName = $provider->systemName;
             $providerData[$provider->name] = $providerInfo;
         }
     }
     $this->providerData = $providerData;
     JFBCFactory::addStylesheet('jfbconnect.css');
     parent::display($tpl);
 }
Esempio n. 3
0
 public function unlink()
 {
     JSession::checkToken('get') or die('Invalid Token');
     $provider = JRequest::getString('provider', '');
     $user = JFactory::getUser();
     $userModel = JFBConnectModelUserMap::getUser($user->get('id'), $provider);
     $provider_user_id = $userModel->getProviderUserId($user->get('id'), $provider);
     $userModel->deleteMapping($provider_user_id, $provider);
     JFBCFactory::log(JText::sprintf('COM_JFBCONNECT_ACCOUNT_LINKED_ACCOUNTS_UNLINK_MESSAGE', $provider));
     $this->setRedirect(JRoute::_('index.php?option=com_jfbconnect&view=account'));
 }
Esempio n. 4
0
 /**
  * Method to delete one or more records.
  *
  * @param   array &$pks  An array of record primary keys.
  *
  * @return  boolean  True if successful, false if an error occurs.
  *
  * Copied from the Joomla legacy folder. Removed content triggers and added deletion of scope for associated user
  */
 public function delete(&$pks)
 {
     $pks = (array) $pks;
     $table = $this->getTable();
     // Iterate the items to delete each one.
     foreach ($pks as $i => $pk) {
         if ($table->load($pk)) {
             if ($this->canDelete($table)) {
                 // Delete any scope for the user associated with this channel
                 $attribs = $table->attribs;
                 if (isset($attribs->user_id)) {
                     $userModel = JFBConnectModelUserMap::getUser($attribs->user_id, $table->provider);
                     $userModel->removeAllScope('channel', $table->id);
                 }
                 if (!$table->delete($pk)) {
                     $this->setError($table->getError());
                     return false;
                 }
             } else {
                 // Prune items that you can't change.
                 unset($pks[$i]);
                 $error = $this->getError();
                 if ($error) {
                     JLog::add($error, JLog::WARNING, 'jerror');
                     return false;
                 } else {
                     JLog::add(JText::_('JLIB_APPLICATION_ERROR_DELETE_NOT_PERMITTED'), JLog::WARNING, 'jerror');
                     return false;
                 }
             }
         } else {
             $this->setError($table->getError());
             return false;
         }
     }
     // Clear the component's cache
     $this->cleanCache();
     return true;
 }
Esempio n. 5
0
 public function enabledForUser()
 {
     if ($this->can_disable) {
         $user = JFactory::getUser();
         $userModel = JFBConnectModelUserMap::getUser($user->get('id'), 'facebook');
         $userData = $userModel->getData();
         $actionsDisabled = $userData->params->get('og_actions_disabled');
         $actId = $this->id;
         if (is_object($actionsDisabled) && property_exists($actionsDisabled, $actId) && $actionsDisabled->{$actId} == 1) {
             return false;
         }
     }
     return true;
 }
Esempio n. 6
0
 private function disableAction($id)
 {
     $user = JFactory::getUser();
     $userModel = JFBConnectModelUserMap::getUser($user->get('id'), 'facebook');
     $userData = $userModel->getData();
     $ogDisabledActions = $userData->params->get('og_actions_disabled', new stdClass());
     $actionModel = $this->getModel('OpenGraphAction', 'JFBConnectModel');
     $action = $actionModel->getAction($id);
     $actionId = $action->id;
     if ($action->can_disable) {
         $ogDisabledActions->{$actionId} = 1;
     }
     $userModel->saveParameter('og_actions_disabled', $ogDisabledActions);
 }
Esempio n. 7
0
 public function onBeforeLogin()
 {
     $userModel = JFBConnectModelUserMap::getUser(JFBCFactory::usermap()->getJoomlaUserId($this->getProviderUserId(), $this->systemName), $this->systemName);
     $requiredScope = $userModel->_data->params->get('required_scope', null);
     if ($requiredScope) {
         $checkScope = array();
         foreach ($requiredScope as $key => $val) {
             $checkScope[] = $key;
         }
         // This may redirect the user back through the login flow to get the specific permissions for them.
         $neededScope = $this->checkRequiredScope($checkScope);
         if (count($neededScope)) {
             $this->fetchNewScope($neededScope);
         }
     }
 }
Esempio n. 8
0
 function login($provider = null)
 {
     if (!is_object($provider)) {
         $provider = JFBCFactory::provider(JRequest::getCmd('provider'));
     }
     // Let the provider do anything it wants before we try to login.
     $provider->onBeforeLogin();
     $loginRegisterModel = $this->getModel('LoginRegister', 'JFBConnectModel');
     // Set a cookie to prevent auto-logging in for the remainder of the session time
     $config = JFactory::getConfig();
     $lifetime = $config->get('lifetime', 15);
     setcookie('jfbconnect_autologin_disable', 1, time() + $lifetime * 60);
     // Not a perfect solution, but fixes autologin loops..
     $app = JFactory::getApplication();
     $providerUserId = $provider->getProviderUserId();
     if (!$providerUserId) {
         # Facebook isn't returning information about this user.  Redirect them.
         JFBCFactory::log(JText::sprintf('COM_JFBCONNECT_UNABLE_TO_RETRIEVE_USER', $provider->name));
         $app->redirect('index.php');
     }
     $userMapModel = JFBCFactory::usermap();
     $jUser = JFactory::getUser();
     if (!$jUser->guest) {
         SCSocialUtilities::clearJFBCNewMappingEnabled();
         if ($userMapModel->map($jUser->get('id'), $providerUserId, strtolower($provider->name), $provider->client->getToken())) {
             JFBCFactory::log(JText::sprintf('COM_JFBCONNECT_MAP_USER_SUCCESS', $provider->name));
         } else {
             JFBCFactory::log(JText::sprintf('COM_JFBCONNECT_MAP_USER_FAIL', $provider->name));
         }
         $return = $loginRegisterModel->getLoginRedirect($provider);
         $app->redirect($return);
     }
     // They're not logged in. Check if they have a Joomla user and log that user in. If not, create them one
     $jUserId = $userMapModel->getJoomlaUserId($providerUserId, strtolower($provider->name));
     if (!$jUserId) {
         $profile = $provider->profile->fetchProfile($providerUserId, array('email'));
         $providerEmail = $profile->get('email', null);
         # Check if automatic email mapping is allowed, and see if that email is registered
         # AND the Facebook user doesn't already have a Joomla account
         if (!$provider->initialRegistration && JFBCFactory::config()->getSetting('facebook_auto_map_by_email')) {
             if ($providerEmail != null) {
                 $jUserEmailId = $userMapModel->getJoomlaUserIdFromEmail($providerEmail);
                 if (!empty($jUserEmailId)) {
                     // Found a user with the same email address
                     // do final check to make sure there isn't a FB account already mapped to it
                     $tempId = $userMapModel->getProviderUserId($jUserEmailId, strtolower($provider->name));
                     if (!$tempId) {
                         SCSocialUtilities::clearJFBCNewMappingEnabled();
                         if ($userMapModel->map($jUserEmailId, $providerUserId, strtolower($provider->name), $provider->client->getToken())) {
                             JFBCFactory::log(JText::sprintf('COM_JFBCONNECT_MAP_USER_SUCCESS', $provider->name));
                             $jUserId = $jUserEmailId;
                             // Update the temp jId so that we login below
                         } else {
                             JFBCFactory::log(JText::sprintf('COM_JFBCONNECT_MAP_USER_FAIL', $provider->name));
                         }
                     }
                 }
             }
         }
         // Check if no mapping, and Automatic Registration is set. If so, auto-create the new user.
         if (!$jUserId && JFBCFactory::config()->getSetting('automatic_registration')) {
             # User is not in system, should create their account automatically
             if ($loginRegisterModel->autoCreateUser($providerUserId, $provider)) {
                 $jUserId = $userMapModel->getJoomlaUserId($providerUserId, strtolower($provider->name));
             }
         }
         // At this point, we have nothing left to do but redirect the user to the registration page
         if (!$jUserId) {
             $return = $loginRegisterModel->getLoginRedirect($provider);
             $app = JFactory::getApplication();
             $regComponent = JFBCFactory::config()->get('registration_component');
             if ($regComponent == 'jfbconnect') {
                 $app->redirect(JRoute::_('index.php?option=com_jfbconnect&view=loginregister&provider=' . strtolower($provider->name) . '&return=' . base64_encode($return), false));
             } else {
                 $app->setUserState('com_jfbconnect.registration.alternateflow', true);
                 $app->setUserState('com_jfbconnect.registration.provider.name', strtolower($provider->name));
                 $app->setUserState('com_jfbconnect.registration.provider.user_id', $providerUserId);
                 $plugins = $app->triggerEvent('socialProfilesGetPlugins');
                 foreach ($plugins as $plugin) {
                     if ($plugin->getName() == $regComponent) {
                         $redirect = $plugin->registration_url;
                     }
                 }
                 if ($redirect) {
                     $app->redirect(JRoute::_($redirect, false));
                 }
             }
         }
     }
     $jUser = JUser::getInstance($jUserId);
     $loginSuccess = false;
     // Try to log the user, but not if blocked and initial registration (then there will be a pretty message on how to activate)
     if (!$provider->initialRegistration || $jUser->get('block') == 0 && $provider->initialRegistration) {
         $options = array('silent' => 1, 'provider' => $provider, 'provider_user_id' => $providerUserId);
         // Disable other authentication messages
         // hack for J3.2.0 bug. Should remove after 3.2.1 is available.
         $password = $provider->secretKey;
         $loginSuccess = $app->login(array('username' => $provider->appId, 'password' => $password), $options);
     }
     if ($loginSuccess) {
         // lets update the user's access token with whatever we just received
         $jUser = JFactory::getUser();
         $userMapModel->updateUserToken($jUser->get('id'), $provider->systemName, $provider->client->getToken());
         // Store Profile URL and Avatar URL
         $userModel = JFBConnectModelUserMap::getUser($jUser->get('id'), $provider->name);
         $userModel->saveParameter('profile_url', JFBCFactory::provider($provider->name)->profile->getProfileUrl($providerUserId));
         $avatarSettings = new JRegistry();
         $avatarSettings->set('width', 50);
         $avatarSettings->set('height', 50);
         $userModel->saveParameter('avatar_thumb', JFBCFactory::provider($provider->name)->profile->getAvatarUrl($providerUserId, false, $avatarSettings));
         if (!$provider->initialRegistration) {
             $args = array(strtolower($provider->name), $jUser->get('id'), $providerUserId);
             $app->triggerEvent('socialProfilesOnLogin', $args);
         }
     }
     JFactory::getApplication()->setUserState('com_jfbconnect.' . strtolower($provider->name) . '.checkForNewMapping', null);
     $allProviders = JFBCFactory::getAllProviders();
     foreach ($allProviders as $p) {
         $p->checkNewMapping();
     }
     $redirect = $loginRegisterModel->getLoginRedirect($provider);
     // Clear the 'alternate flow' session bit to prevent further alterations to reg pages for this user/session
     $app->setUserState('com_jfbconnect.registration.alternateflow', false);
     $app->redirect($redirect);
 }