public function onAfterInitialise() { $app = JFactory::getApplication(); if (!$app->isAdmin()) { return; } $option = JFactory::getApplication()->input->getWord('option', ''); $view = JFactory::getApplication()->input->getWord('view', ''); try { if ($option == 'com_installer' && $view == 'update') { $subscriber_info = $this->container->storageservice->getSubscriberInfo(); if (is_null($subscriber_info)) { $this->container->storageservice->removeSubscriberInfo(); $subscriber_info = new RokUpdater_Subscriber_Info(); } // check if the access token has expired if ($subscriber_info->refresh_token != null && $subscriber_info->expires < time()) { $refresh_result = $this->container->messageservice->requestAccessTokenRefresh($subscriber_info->refresh_token, $this->container->site_id); if ($refresh_result->getStatus() == RokUpdater_Message_RequestStatus::SUCCESS) { $this->container->storageservice->storeSubscriberInfo(RokUpdater_Subscriber_Factory::createFromOAuthAccessTokenResponse($refresh_result)); $this->container->storageservice->updateAccessToken($this->container->site_id, $refresh_result->getOauthInfo()->getAccessToken()); } else { $this->container->storageservice->removeSubscriberInfo(); $this->container->storageservice->updateAccessToken($this->container->site_id); } $this->container->storageservice->forceUpdatesRefresh(); } } } catch (Exception $e) { $this->_subject->setError($e->getMessage()); return false; } return true; }
/** * */ public function run() { $container = RokUpdater_ServiceProvider::getInstance(); $user = JFactory::getUser(); $result = new stdClass(); $result->status = "error"; $result->message = ""; $lang = JFactory::getLanguage(); $lang->load('plg_system_rokupdater', JPATH_ADMINISTRATOR, $lang->getDefault(), false, false); $lang->load('plg_system_rokupdater', JPATH_ADMINISTRATOR, null, false, false); $lang->load('plg_system_rokupdater', JPATH_PLUGINS . '/system/rokupdater', $lang->getDefault(), false, false); $lang->load('plg_system_rokupdater', JPATH_PLUGINS . '/system/rokupdater', null, false, false); try { // Check for if ($user->id == 0 || !$user->authorise('core.manage', 'com_installer')) { throw new RokUpdater_Exception('ROKUPDATER_INVALID_ACCESS'); } $input = JFactory::getApplication()->input; $username = $input->post->get('userid', null, 'STRING'); $password = $input->post->get('pswrd', null, 'STRING'); if (empty($username) || empty($password)) { throw new RokUpdater_Exception('ROKUPDATER_ERROR_NEED_USERNAME_AND_PASSSWORD'); } $result = $container->messageservice->requestAccessToken($username, $password, $container->site_id); if ($result->getStatus() !== RokUpdater_Message_RequestStatus::SUCCESS) { throw new RokUpdater_Exception($result->getMessage()); } // store the access token info to the extension data $container->storageservice->storeSubscriberInfo(RokUpdater_Subscriber_Factory::createFromOAuthAccessTokenResponse($result)); // update the update_site urls with the current access token $container->storageservice->updateAccessToken($container->site_id, $result->getOauthInfo()->getAccessToken()); // refresh the updates $container->storageservice->forceUpdatesRefresh(); $result->status = 'success'; $result->message = JText::_('ROKUPDATER_SUCCESS_LOGIN_MESSAGE'); } catch (RokUpdater_Exception $roe) { $result->status = 'error'; $result->message = JText::_($roe->getMessage()); } return json_encode($result); }
/** * */ public function removeSubscriberInfo($notice = null) { $subscriber_info = RokUpdater_Subscriber_Factory::createEmpty($notice); $this->storeSubscriberInfo($subscriber_info); }