diff --git a/administrator/components/com_config/Controller/ApplicationController.php b/administrator/components/com_config/Controller/ApplicationController.php index 2978d1a828185..d470b1d447516 100644 --- a/administrator/components/com_config/Controller/ApplicationController.php +++ b/administrator/components/com_config/Controller/ApplicationController.php @@ -12,9 +12,11 @@ defined('_JEXEC') or die; use Joomla\CMS\Application\CMSApplication; +use Joomla\CMS\Language\Text; use Joomla\CMS\MVC\Controller\BaseController; use Joomla\CMS\MVC\Factory\MVCFactoryInterface; use Joomla\CMS\Response\JsonResponse; +use Joomla\CMS\Session\Session; /** * Controller for global configuration @@ -208,9 +210,9 @@ public function sendtestmail() $this->app->sendHeaders(); // Check if user token is valid. - if (!\JSession::checkToken('get')) + if (!Session::checkToken('get')) { - $this->app->enqueueMessage(\JText::_('JINVALID_TOKEN'), 'error'); + $this->app->enqueueMessage(Text::_('JINVALID_TOKEN'), 'error'); echo new JsonResponse; $this->app->close(); } @@ -218,7 +220,7 @@ public function sendtestmail() // Check if the user is authorized to do this. if (!$this->app->getIdentity()->authorise('core.admin')) { - $this->app->enqueueMessage(\JText::_('JERROR_ALERTNOAUTHOR'), 'error'); + $this->app->enqueueMessage(Text::_('JERROR_ALERTNOAUTHOR'), 'error'); echo new JsonResponse; $this->app->close(); } @@ -226,7 +228,9 @@ public function sendtestmail() /** @var \Joomla\Component\Config\Administrator\Model\ApplicationModel $model */ $model = $this->getModel('Application', 'Administrator'); - echo new JsonResponse($model->sendTestMail()); + $result = $model->sendTestMail(); + + echo new JsonResponse($result, null, !$result); $this->app->close(); } diff --git a/administrator/components/com_config/Model/ApplicationModel.php b/administrator/components/com_config/Model/ApplicationModel.php index 60e1e2cb96538..81ddeb426ee3c 100644 --- a/administrator/components/com_config/Model/ApplicationModel.php +++ b/administrator/components/com_config/Model/ApplicationModel.php @@ -14,6 +14,8 @@ use Joomla\CMS\Access\Access as JAccess; use Joomla\CMS\Access\Rules as JAccessRules; use Joomla\CMS\Component\ComponentHelper; +use Joomla\CMS\Factory; +use Joomla\CMS\Language\Text; use Joomla\CMS\MVC\Model\FormModel; use Joomla\CMS\Table\Asset; use Joomla\CMS\Table\Table; @@ -880,8 +882,8 @@ public function storePermissions($permission = null) public function sendTestMail() { // Set the new values to test with the current settings - $app = \JFactory::getApplication(); - $input = $app->input; + $app = Factory::getApplication(); + $input = $app->input->json; $app->set('smtpauth', $input->get('smtpauth')); $app->set('smtpuser', $input->get('smtpuser', '', 'STRING')); @@ -894,30 +896,30 @@ public function sendTestMail() $app->set('mailer', $input->get('mailer')); $app->set('mailonline', $input->get('mailonline')); - $mail = \JFactory::getMailer(); + $mail = Factory::getMailer(); // Prepare email and send try to send it - $mailSubject = \JText::sprintf('COM_CONFIG_SENDMAIL_SUBJECT', $app->get('sitename')); - $mailBody = \JText::sprintf('COM_CONFIG_SENDMAIL_BODY', \JText::_('COM_CONFIG_SENDMAIL_METHOD_' . strtoupper($mail->Mailer))); + $mailSubject = Text::sprintf('COM_CONFIG_SENDMAIL_SUBJECT', $app->get('sitename')); + $mailBody = Text::sprintf('COM_CONFIG_SENDMAIL_BODY', Text::_('COM_CONFIG_SENDMAIL_METHOD_' . strtoupper($mail->Mailer))); if ($mail->sendMail($app->get('mailfrom'), $app->get('fromname'), $app->get('mailfrom'), $mailSubject, $mailBody) === true) { - $methodName = \JText::_('COM_CONFIG_SENDMAIL_METHOD_' . strtoupper($mail->Mailer)); + $methodName = Text::_('COM_CONFIG_SENDMAIL_METHOD_' . strtoupper($mail->Mailer)); // If JMail send the mail using PHP Mail as fallback. if ($mail->Mailer != $app->get('mailer')) { - $app->enqueueMessage(\JText::sprintf('COM_CONFIG_SENDMAIL_SUCCESS_FALLBACK', $app->get('mailfrom'), $methodName), 'warning'); + $app->enqueueMessage(Text::sprintf('COM_CONFIG_SENDMAIL_SUCCESS_FALLBACK', $app->get('mailfrom'), $methodName), 'warning'); } else { - $app->enqueueMessage(\JText::sprintf('COM_CONFIG_SENDMAIL_SUCCESS', $app->get('mailfrom'), $methodName), 'message'); + $app->enqueueMessage(Text::sprintf('COM_CONFIG_SENDMAIL_SUCCESS', $app->get('mailfrom'), $methodName), 'message'); } return true; } - $app->enqueueMessage(\JText::_('COM_CONFIG_SENDMAIL_ERROR'), 'error'); + $app->enqueueMessage(Text::_('COM_CONFIG_SENDMAIL_ERROR'), 'error'); return false; } diff --git a/administrator/language/en-GB/en-GB.com_config.ini b/administrator/language/en-GB/en-GB.com_config.ini index cd4fb4087d118..6ac9bd003e7fb 100644 --- a/administrator/language/en-GB/en-GB.com_config.ini +++ b/administrator/language/en-GB/en-GB.com_config.ini @@ -165,6 +165,9 @@ COM_CONFIG_SAVE_SUCCESS="Configuration saved." COM_CONFIG_SENDMAIL_ACTION_BUTTON="Send Test Mail" COM_CONFIG_SENDMAIL_BODY="This is a test mail sent using "_QQ_"%s"_QQ_". Your email settings are correct!" COM_CONFIG_SENDMAIL_ERROR="Test mail could not be sent." +COM_CONFIG_SENDMAIL_METHOD_MAIL="PHP Mail" +COM_CONFIG_SENDMAIL_METHOD_SENDMAIL="Sendmail" +COM_CONFIG_SENDMAIL_METHOD_SMTP="SMTP" COM_CONFIG_SENDMAIL_SUBJECT="Test mail from %s" COM_CONFIG_SENDMAIL_SUCCESS="The email was sent to %s using %s. You should check that you've received the test email." COM_CONFIG_SENDMAIL_SUCCESS_FALLBACK="The email was sent to %s but using %s as fallback. You should check that you've received the test email." diff --git a/libraries/src/Factory.php b/libraries/src/Factory.php index 5bf707d3c99a1..3171987f1a945 100644 --- a/libraries/src/Factory.php +++ b/libraries/src/Factory.php @@ -385,7 +385,7 @@ public static function getDbo() * * Returns the global {@link \JMail} object, only creating it if it doesn't already exist. * - * @return \JMail object + * @return Mail object * * @see JMail * @since 11.1 diff --git a/libraries/src/Session/Session.php b/libraries/src/Session/Session.php index e4df2fa453b15..969dc7e485d84 100644 --- a/libraries/src/Session/Session.php +++ b/libraries/src/Session/Session.php @@ -11,6 +11,9 @@ defined('JPATH_PLATFORM') or die; use Joomla\CMS\Application\ApplicationHelper; +use Joomla\CMS\Factory; +use Joomla\CMS\Language\Text; +use Joomla\CMS\Router\Route; use Joomla\Session\Session as BaseSession; /** @@ -33,16 +36,22 @@ class Session extends BaseSession */ public static function checkToken($method = 'post') { - $app = \JFactory::getApplication(); + $app = Factory::getApplication(); $token = static::getFormToken(); + // Check from header first + if ($token === $app->input->server->get('HTTP_X_CSRF_TOKEN', '', 'alnum')) + { + return true; + } + if (!$app->input->$method->get($token, '', 'alnum')) { if ($app->getSession()->isNew()) { // Redirect to login screen. - $app->enqueueMessage(\JText::_('JLIB_ENVIRONMENT_SESSION_EXPIRED'), 'warning'); - $app->redirect(\JRoute::_('index.php')); + $app->enqueueMessage(Text::_('JLIB_ENVIRONMENT_SESSION_EXPIRED'), 'warning'); + $app->redirect(Route::_('index.php')); return true; } diff --git a/media/system/js/core.js b/media/system/js/core.js index 27e1ca67804a3..f03d2fb69bc4f 100644 --- a/media/system/js/core.js +++ b/media/system/js/core.js @@ -494,7 +494,7 @@ Joomla.editors.instances = Joomla.editors.instances || { { msg.error = [ Joomla.JText._('JLIB_JS_AJAX_ERROR_CONNECTION_ABORT') ]; } - // For vannila XHR + // For vanilla XHR else if (xhr.responseJSON && xhr.responseJSON.message) { msg.error = [ Joomla.JText._('JLIB_JS_AJAX_ERROR_OTHER').replace('%s', xhr.status) + ' ' + xhr.responseJSON.message + '' ]; diff --git a/media/system/js/fields/sendtestmail.js b/media/system/js/fields/sendtestmail.js index 52dd21ce86364..dd1f6f6b74244 100644 --- a/media/system/js/fields/sendtestmail.js +++ b/media/system/js/fields/sendtestmail.js @@ -4,51 +4,59 @@ * @license GNU General Public License version 2 or later; see LICENSE.txt */ -/** - * Calls the sending process of the config class - */ -"use strict"; - -var sendTestMail = function() { - - var email_data = { - smtpauth : document.querySelector('[name="jform[smtpauth]"]').value, - smtpuser : document.querySelector('[name="jform[smtpuser]"]').value, - smtppass : document.querySelector('[name="jform[smtppass]"]').value, - smtphost : document.querySelector('[name="jform[smtphost]"]').value, - smtpsecure: document.querySelector('[name="jform[smtpsecure]"]').value, - smtpport : document.querySelector('[name="jform[smtpport]"]').value, - mailfrom : document.querySelector('[name="jform[mailfrom]"]').value, - fromname : document.querySelector('[name="jform[fromname]"]').value, - mailer : document.querySelector('[name="jform[mailer]"]').value, - mailonline: document.querySelector('[name="jform[mailonline]"]').value - }; +(function() { + "use strict"; + + /** + * Calls the sending process of the config class + */ + var sendTestMail = function() { + + var email_data = { + smtpauth : document.querySelector('[name="jform[smtpauth]"]:checked').value, + smtpuser : document.querySelector('[name="jform[smtpuser]"]').value, + smtppass : document.querySelector('[name="jform[smtppass]"]').value, + smtphost : document.querySelector('[name="jform[smtphost]"]').value, + smtpsecure: document.querySelector('[name="jform[smtpsecure]"]').value, + smtpport : document.querySelector('[name="jform[smtpport]"]').value, + mailfrom : document.querySelector('[name="jform[mailfrom]"]').value, + fromname : document.querySelector('[name="jform[fromname]"]').value, + mailer : document.querySelector('[name="jform[mailer]"]').value, + mailonline: document.querySelector('[name="jform[mailonline]"]:checked').value + }; - // Remove js messages, if they exist. - Joomla.removeMessages(); - - Joomla.request( - { - url: document.getElementById('sendtestmail').getAttribute('data-ajaxuri'), - method: 'POST', - data: JSON.stringify(email_data), - perform: true, - headers: {'Content-Type': 'application/x-www-form-urlencoded'}, - onSuccess: function(response, xhr) + // Remove js messages, if they exist. + Joomla.removeMessages(); + + Joomla.request( { - response = JSON.parse(response); - if (typeof response.messages == 'object' && response.messages !== null) { - Joomla.renderMessages(response.messages); + url: document.getElementById('sendtestmail').getAttribute('data-ajaxuri'), + method: 'POST', + data: JSON.stringify(email_data), + perform: true, + headers: {'Content-Type': 'application/x-www-form-urlencoded'}, + onSuccess: function(response, xhr) + { + response = JSON.parse(response); + + if (response.error) { + Joomla.renderMessages({error: [response.message]}); + return; + } + + if (typeof response.messages === 'object' && response.messages !== null) { + Joomla.renderMessages(response.messages); + } + }, + onError: function(xhr) + { + Joomla.renderMessages(Joomla.ajaxErrorsMessages(xhr)); } - }, - onError: function(xhr) - { - Joomla.renderMessages(Joomla.ajaxErrorsMessages(xhr)); } - } - ); -}; + ); + }; -document.addEventListener('DOMContentLoaded', function() { - document.getElementById('sendtestmail').addEventListener('click', sendTestMail); -}); + document.addEventListener('DOMContentLoaded', function() { + document.getElementById('sendtestmail').addEventListener('click', sendTestMail); + }); +})(); diff --git a/media/system/js/fields/sendtestmail.min.js b/media/system/js/fields/sendtestmail.min.js index 99614d950a288..6d9a7c7e30caf 100644 --- a/media/system/js/fields/sendtestmail.min.js +++ b/media/system/js/fields/sendtestmail.min.js @@ -1 +1 @@ -"use strict";var sendTestMail=function(){var e={smtpauth:document.querySelector('[name="jform[smtpauth]"]').value,smtpuser:document.querySelector('[name="jform[smtpuser]"]').value,smtppass:document.querySelector('[name="jform[smtppass]"]').value,smtphost:document.querySelector('[name="jform[smtphost]"]').value,smtpsecure:document.querySelector('[name="jform[smtpsecure]"]').value,smtpport:document.querySelector('[name="jform[smtpport]"]').value,mailfrom:document.querySelector('[name="jform[mailfrom]"]').value,fromname:document.querySelector('[name="jform[fromname]"]').value,mailer:document.querySelector('[name="jform[mailer]"]').value,mailonline:document.querySelector('[name="jform[mailonline]"]').value};Joomla.removeMessages(),Joomla.request({url:document.getElementById("sendtestmail").getAttribute("data-ajaxuri"),method:"POST",data:JSON.stringify(e),perform:!0,headers:{"Content-Type":"application/x-www-form-urlencoded"},onSuccess:function(e,t){"object"==typeof(e=JSON.parse(e)).messages&&null!==e.messages&&Joomla.renderMessages(e.messages)},onError:function(e){Joomla.renderMessages(Joomla.ajaxErrorsMessages(e))}})};document.addEventListener("DOMContentLoaded",function(){document.getElementById("sendtestmail").addEventListener("click",sendTestMail)}); \ No newline at end of file +!function(){"use strict";var e=function(){var e={smtpauth:document.querySelector('[name="jform[smtpauth]"]:checked').value,smtpuser:document.querySelector('[name="jform[smtpuser]"]').value,smtppass:document.querySelector('[name="jform[smtppass]"]').value,smtphost:document.querySelector('[name="jform[smtphost]"]').value,smtpsecure:document.querySelector('[name="jform[smtpsecure]"]').value,smtpport:document.querySelector('[name="jform[smtpport]"]').value,mailfrom:document.querySelector('[name="jform[mailfrom]"]').value,fromname:document.querySelector('[name="jform[fromname]"]').value,mailer:document.querySelector('[name="jform[mailer]"]').value,mailonline:document.querySelector('[name="jform[mailonline]"]:checked').value};Joomla.removeMessages(),Joomla.request({url:document.getElementById("sendtestmail").getAttribute("data-ajaxuri"),method:"POST",data:JSON.stringify(e),perform:!0,headers:{"Content-Type":"application/x-www-form-urlencoded"},onSuccess:function(e,o){(e=JSON.parse(e)).error?Joomla.renderMessages({error:[e.message]}):"object"==typeof e.messages&&null!==e.messages&&Joomla.renderMessages(e.messages)},onError:function(e){Joomla.renderMessages(Joomla.ajaxErrorsMessages(e))}})};document.addEventListener("DOMContentLoaded",function(){document.getElementById("sendtestmail").addEventListener("click",e)})}();