diff options
Diffstat (limited to 'src/service')
| -rw-r--r-- | src/service/AppMode.php | 56 | ||||
| -rw-r--r-- | src/service/Config.php | 10 | ||||
| -rw-r--r-- | src/service/EmailService.php | 8 | ||||
| -rw-r--r-- | src/service/router.php | 12 |
4 files changed, 22 insertions, 64 deletions
diff --git a/src/service/AppMode.php b/src/service/AppMode.php deleted file mode 100644 index 60b58bd..0000000 --- a/src/service/AppMode.php +++ /dev/null | |||
| @@ -1,56 +0,0 @@ | |||
| 1 | <?php | ||
| 2 | // src/service/AppMode.php | ||
| 3 | |||
| 4 | // comme dans AppMetadata, prévoir d'ajouter des champs "since" et "by" (qui a changé quoi quel jour?) | ||
| 5 | |||
| 6 | declare(strict_types=1); | ||
| 7 | |||
| 8 | use App\Entity\AppMetadata; | ||
| 9 | use Doctrine\ORM\EntityManager; | ||
| 10 | |||
| 11 | class AppMode | ||
| 12 | { | ||
| 13 | private static string $mode; | ||
| 14 | |||
| 15 | public static function load(EntityManager $entityManager): void | ||
| 16 | { | ||
| 17 | $metadata = $entityManager->getRepository(AppMetadata::class)->find('mode'); | ||
| 18 | if(!$metadata){ | ||
| 19 | self::$mode = 'maintenance'; | ||
| 20 | } | ||
| 21 | else{ | ||
| 22 | self::$mode = $metadata->getValue(); | ||
| 23 | } | ||
| 24 | } | ||
| 25 | |||
| 26 | public static function is(string $mode): bool | ||
| 27 | { | ||
| 28 | return self::$mode === $mode; | ||
| 29 | } | ||
| 30 | |||
| 31 | public static function get(): string | ||
| 32 | { | ||
| 33 | return self::$mode; | ||
| 34 | } | ||
| 35 | |||
| 36 | public static function set(EntityManager $entityManager, string $mode): void | ||
| 37 | { | ||
| 38 | self::$mode = $mode; | ||
| 39 | |||
| 40 | $metadata = $entityManager->find(AppMetadata::class, 'mode'); | ||
| 41 | if($metadata){ | ||
| 42 | $metadata->setValue($mode); | ||
| 43 | } | ||
| 44 | else{ | ||
| 45 | $metadata = new AppMetadata('mode', $mode); | ||
| 46 | $entityManager->persist($metadata); | ||
| 47 | } | ||
| 48 | $entityManager->flush(); | ||
| 49 | |||
| 50 | /*self::$data = [ | ||
| 51 | 'mode' => $mode, | ||
| 52 | 'since' => (new DateTimeImmutable())->format('c'), | ||
| 53 | 'by' => $by, | ||
| 54 | ];*/ | ||
| 55 | } | ||
| 56 | } \ No newline at end of file | ||
diff --git a/src/service/Config.php b/src/service/Config.php index e59f728..7077e01 100644 --- a/src/service/Config.php +++ b/src/service/Config.php | |||
| @@ -18,15 +18,17 @@ class Config | |||
| 18 | static public string $index_path = ''; | 18 | static public string $index_path = ''; |
| 19 | static public string $port = '80'; | 19 | static public string $port = '80'; |
| 20 | 20 | ||
| 21 | // e-mails | 21 | // envoi e-mails |
| 22 | static public string $smtp_host = ''; | 22 | static public string $smtp_host = ''; |
| 23 | static public string $smtp_username = ''; | 23 | static public string $smtp_username = ''; |
| 24 | static public string $smtp_password = ''; | 24 | static public string $smtp_password = ''; |
| 25 | static public string $smtp_secure = ''; // tls (smarttls) ou ssl (smtps) ou plain_text/chaine vide | 25 | static public string $smtp_secure = ''; // tls (smarttls) ou ssl (smtps) ou plain_text/chaine vide |
| 26 | static public string $email_from = 'mon_adresse@email.fr'; | 26 | |
| 27 | // destination e-mails | ||
| 28 | static public string $email_from = ''; // correspondant affiché dans la boite de réception | ||
| 27 | static public string $email_from_name = 'site web'; | 29 | static public string $email_from_name = 'site web'; |
| 28 | static public string $email_dest = ''; | 30 | static public string $email_dest = ''; // destinataire affiché dans la boite de réception |
| 29 | static public string $email_dest_name = 'destinataire formulaire'; | 31 | static public string $email_dest_name = 'moi'; |
| 30 | 32 | ||
| 31 | // copier dans ce tableau les variables contenant des chemins | 33 | // copier dans ce tableau les variables contenant des chemins |
| 32 | static private array $path_vars = []; | 34 | static private array $path_vars = []; |
diff --git a/src/service/EmailService.php b/src/service/EmailService.php index 6f4e93d..0ea8f39 100644 --- a/src/service/EmailService.php +++ b/src/service/EmailService.php | |||
| @@ -22,8 +22,10 @@ class EmailService | |||
| 22 | $smtp_secure = $form_data->getData()['smtp_secure'] ?? Config::$smtp_secure; | 22 | $smtp_secure = $form_data->getData()['smtp_secure'] ?? Config::$smtp_secure; |
| 23 | $smtp_username = $form_data->getData()['smtp_username'] ?? Config::$smtp_username; | 23 | $smtp_username = $form_data->getData()['smtp_username'] ?? Config::$smtp_username; |
| 24 | $smtp_password = $form_data->getData()['smtp_password'] ?? Config::$smtp_password; | 24 | $smtp_password = $form_data->getData()['smtp_password'] ?? Config::$smtp_password; |
| 25 | $email_from = $form_data->getData()['email_from'] ?? Config::$email_from; // une adresse bidon est donnée à setFrom() | 25 | |
| 26 | $email_from_name = $form_data->getData()['email_from_name'] ?? Config::$email_from_name; // = site web | 26 | $email_from = $form_data->getData()['email_from'] ?? Config::$email_from; // adresse de l'expéditeur affichée |
| 27 | $email_from = empty($email_from) ? $smtp_username : $email_from; // si vide | ||
| 28 | $email_from_name = $form_data->getData()['email_from_name'] ?? Config::$email_from_name; // = nom de l'expéditeur affiché | ||
| 27 | $email_dest = $form_data->getData()['email_dest'] ?? Config::$email_dest; | 29 | $email_dest = $form_data->getData()['email_dest'] ?? Config::$email_dest; |
| 28 | $email_dest_name = $form_data->getData()['email_dest_name'] ?? Config::$email_dest_name; // = destinataire formulaire | 30 | $email_dest_name = $form_data->getData()['email_dest_name'] ?? Config::$email_dest_name; // = destinataire formulaire |
| 29 | 31 | ||
| @@ -67,7 +69,7 @@ class EmailService | |||
| 67 | 69 | ||
| 68 | // copie en BDD | 70 | // copie en BDD |
| 69 | if(!$test_email && ($form_data->getData()['keep_emails'] ?? self::KEEP_EMAILS_DEFAULT)){ | 71 | if(!$test_email && ($form_data->getData()['keep_emails'] ?? self::KEEP_EMAILS_DEFAULT)){ |
| 70 | $db_email = new Email($name, $email, Config::$email_dest, $message, $form_data); | 72 | $db_email = new Email($name, $email, $email_dest, $message, $form_data); |
| 71 | $entityManager->persist($db_email); | 73 | $entityManager->persist($db_email); |
| 72 | self::updateLastContactDate($entityManager, $email); | 74 | self::updateLastContactDate($entityManager, $email); |
| 73 | $entityManager->flush(); | 75 | $entityManager->flush(); |
diff --git a/src/service/router.php b/src/service/router.php index fc6b028..508721c 100644 --- a/src/service/router.php +++ b/src/service/router.php | |||
| @@ -39,7 +39,7 @@ if($request->getMethod() === 'GET'){ | |||
| 39 | } | 39 | } |
| 40 | 40 | ||
| 41 | // pages interdites | 41 | // pages interdites |
| 42 | if(!IS_ADMIN && in_array(CURRENT_PAGE, ['menu_paths', 'new_page', 'user_edit', 'emails'])){ | 42 | if(!IS_ADMIN && in_array(CURRENT_PAGE, ['menu_paths', 'new_page', 'user_edit', 'emails', 'maintenance'])){ |
| 43 | header('Location: ' . new URL); | 43 | header('Location: ' . new URL); |
| 44 | die; | 44 | die; |
| 45 | } | 45 | } |
| @@ -154,6 +154,16 @@ elseif($request->getMethod() === 'POST'){ | |||
| 154 | elseif($request->query->get('action') === 'remove_event'){ | 154 | elseif($request->query->get('action') === 'remove_event'){ |
| 155 | CalendarController::removeEvent($json, $entityManager); | 155 | CalendarController::removeEvent($json, $entityManager); |
| 156 | } | 156 | } |
| 157 | |||
| 158 | /* -- mode maintenance -- */ | ||
| 159 | elseif($request->query->get('action') === 'get_logs'){ | ||
| 160 | MaintenanceController::getLogs($entityManager); | ||
| 161 | die; | ||
| 162 | } | ||
| 163 | elseif($request->query->get('action') === 'erase_logs'){ | ||
| 164 | MaintenanceController::eraseLogs($entityManager); | ||
| 165 | die; | ||
| 166 | } | ||
| 157 | else{ | 167 | else{ |
| 158 | echo json_encode(['success' => false]); | 168 | echo json_encode(['success' => false]); |
| 159 | die; | 169 | die; |
