-
-
Notifications
You must be signed in to change notification settings - Fork 256
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: added controller for configuration, removed old code
- Loading branch information
Showing
6 changed files
with
68 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
phpmyfaq/src/phpMyFAQ/Controller/Administration/ConfigurationController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
namespace phpMyFAQ\Controller\Administration; | ||
|
||
use phpMyFAQ\Configuration; | ||
use phpMyFAQ\Controller; | ||
use phpMyFAQ\Core\Exception; | ||
use phpMyFAQ\Mail; | ||
use phpMyFAQ\Session\Token; | ||
use phpMyFAQ\Translation; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\Mailer\Exception\TransportExceptionInterface; | ||
use Symfony\Component\Routing\Annotation\Route; | ||
|
||
class ConfigurationController extends Controller | ||
{ | ||
#[Route('admin/api/configuration/send-test-mail')] | ||
public function sendTestMail(Request $request): JsonResponse | ||
{ | ||
$response = new JsonResponse(); | ||
$configuration = Configuration::getConfigurationInstance(); | ||
|
||
$data = json_decode($request->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; | ||
} | ||
} |