diff --git a/nginx.conf b/nginx.conf index 67e09e6b85..86b89cb908 100644 --- a/nginx.conf +++ b/nginx.conf @@ -140,6 +140,7 @@ server { # Administration API rewrite admin/api/category/permissions /admin/api/index.php last; rewrite admin/api/category/update-order /admin/api/index.php last; + rewrite admin/api/configuration/send-test-mail /admin/api/index.php last; rewrite admin/api/content/attachments /admin/api/index.php last; rewrite admin/api/content/attachments/upload /admin/api/index.php last; rewrite admin/api/content/comments /admin/api/index.php last; diff --git a/phpmyfaq/.htaccess b/phpmyfaq/.htaccess index 7d0573163b..8e159a6e1a 100644 --- a/phpmyfaq/.htaccess +++ b/phpmyfaq/.htaccess @@ -150,6 +150,7 @@ RewriteRule api/setup/update-database api/index.php # Administration API RewriteRule admin/api/category/permissions admin/api/index.php RewriteRule admin/api/category/update-order admin/api/index.php +RewriteRule admin/api/configuration/send-test-mail admin/api/index.php RewriteRule admin/api/content/attachments admin/api/index.php RewriteRule admin/api/content/attachments/upload admin/api/index.php RewriteRule admin/api/content/comments admin/api/index.php diff --git a/phpmyfaq/admin/api/configuration.php b/phpmyfaq/admin/api/configuration.php index adf7770a51..51b35d6355 100644 --- a/phpmyfaq/admin/api/configuration.php +++ b/phpmyfaq/admin/api/configuration.php @@ -319,33 +319,4 @@ $response->setData($payload); $response->send(); break; - - case 'send-test-mail': - $json = file_get_contents('php://input', true); - $postData = json_decode($json); - - if (!Token::getInstance()->verifyToken('configuration', $postData->csrf)) { - $response->setStatusCode(Response::HTTP_UNAUTHORIZED); - $response->setData(['error' => Translation::get('err_NotAuth')]); - $response->send(); - exit(); - } - - try { - $mailer = new Mail($faqConfig); - $mailer->setReplyTo($faqConfig->getAdminEmail()); - $mailer->addTo($faqConfig->getAdminEmail()); - $mailer->subject = $faqConfig->getTitle() . ': Mail test successful.'; - $mailer->message = 'It works on my machine. 🚀'; - $result = $mailer->send(); - - $response->setStatusCode(Response::HTTP_OK); - $response->setData(['success' => $result]); - } catch (Exception | TransportExceptionInterface $e) { - $response->setStatusCode(Response::HTTP_BAD_REQUEST); - $response->setData(['error' => $e->getMessage()]); - } - - $response->send(); - break; } diff --git a/phpmyfaq/admin/assets/js/configuration.js b/phpmyfaq/admin/assets/js/configuration.js index 54059cab3a..b9ac02d3ac 100644 --- a/phpmyfaq/admin/assets/js/configuration.js +++ b/phpmyfaq/admin/assets/js/configuration.js @@ -36,7 +36,7 @@ const handleSendTestMail = () => { if (button) { const csrf = document.querySelector('#pmf-csrf-token').value; - fetch('index.php?action=ajax&ajax=config&ajaxaction=send-test-mail', { + fetch('./api/configuration/send-test-mail', { method: 'POST', headers: { Accept: 'application/json, text/plain, */*', diff --git a/phpmyfaq/src/admin-routes.php b/phpmyfaq/src/admin-routes.php index 8f050fe3e5..3131e9596b 100644 --- a/phpmyfaq/src/admin-routes.php +++ b/phpmyfaq/src/admin-routes.php @@ -18,6 +18,7 @@ use phpMyFAQ\Controller\Administration\AttachmentController; use phpMyFAQ\Controller\Administration\CategoryController; use phpMyFAQ\Controller\Administration\CommentController; +use phpMyFAQ\Controller\Administration\ConfigurationController; use phpMyFAQ\Controller\Administration\DashboardController; use phpMyFAQ\Controller\Administration\ElasticsearchController; use phpMyFAQ\Controller\Administration\GroupController; @@ -82,6 +83,20 @@ new Route('/content/comments', ['_controller' => [CommentController::class, 'delete'], '_methods' => 'DELETE']) ); +// +// Configuration API +// +$routes->add( + 'admin.api.configuration.send-test-mail', + new Route( + '/configuration/send-test-mail', + [ + '_controller' => [ConfigurationController::class, 'sendTestMail'], + '_methods' => 'POST' + ] + ) +); + // // Image API // diff --git a/phpmyfaq/src/phpMyFAQ/Controller/Administration/ConfigurationController.php b/phpmyfaq/src/phpMyFAQ/Controller/Administration/ConfigurationController.php new file mode 100644 index 0000000000..349e51acbf --- /dev/null +++ b/phpmyfaq/src/phpMyFAQ/Controller/Administration/ConfigurationController.php @@ -0,0 +1,50 @@ +getContent()); + + if (!Token::getInstance()->verifyToken('configuration', $data->csrf)) { + $response->setStatusCode(Response::HTTP_UNAUTHORIZED); + $response->setData(['error' => Translation::get('err_NotAuth')]); + return $response; + } + + try { + $mailer = new Mail($configuration); + $mailer->setReplyTo($configuration->getAdminEmail()); + $mailer->addTo($configuration->getAdminEmail()); + $mailer->subject = $configuration->getTitle() . ': Mail test successful.'; + $mailer->message = 'It works on my machine. 🚀'; + $result = $mailer->send(); + + $response->setStatusCode(Response::HTTP_OK); + $response->setData(['success' => $result]); + } catch (Exception | TransportExceptionInterface $e) { + $response->setStatusCode(Response::HTTP_BAD_REQUEST); + $response->setData(['error' => $e->getMessage()]); + } + + return $response; + } +}