← All changes
|
front/FrontControllers/FrontservicesController.php
+9
-1
10.2.2
→
11.1.0
View file →
| @@ -25,17 +25,22 @@ | ||
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | public function sendinblue(): void |
| 28 | 28 | { |
| 29 | + // Check security key | |
| 29 | 30 | $securityKey = acym_getVar('string', 'seckey'); |
| 30 | - if (empty($securityKey) || $securityKey !== $this->config->get('sendinblue_webhooks_seckey')) exit; | |
| 31 | + $storedKey = $this->config->get('sendinblue_webhooks_seckey'); | |
| 32 | + if (empty($securityKey) || empty($storedKey) || !hash_equals((string)$storedKey, (string)$securityKey)) exit; | |
| 31 | 33 | |
| 34 | + // Check if sending method is sendinblue | |
| 32 | 35 | $mailerMethod = $this->config->get('mailer_method'); |
| 33 | 36 | if (!in_array($mailerMethod, ['brevo-smtp', 'sendinblue'])) exit; |
| 34 | 37 | |
| 38 | + // Get the data passed by Sendinblue | |
| 35 | 39 | $data = acym_getJsonData(); |
| 36 | 40 | if (empty($data['email'])) exit; |
| 37 | 41 | |
| 42 | + // Get the user from the email | |
| 38 | 43 | $userClass = new UserClass(); |
| 39 | 44 | $user = $userClass->getOneByEmail($data['email']); |
| 40 | 45 | if (empty($user)) exit; |
| 41 | 46 | |
| @@ -40,12 +45,14 @@ | ||
| 40 | 45 | if (empty($user)) exit; |
| 41 | 46 | |
| 42 | 47 | $action = empty($data['event']) ? 'brevo' : $data['event']; |
| 43 | 48 | |
| 49 | + // Get the related email id if there is one | |
| 44 | 50 | $mailId = 0; |
| 45 | 51 | if (!empty($data['campaign name']) && strpos($data['campaign name'], 'AcyMailing Mail ') === 0) { |
| 46 | 52 | $mailId = preg_replace('#^AcyMailing Mail (\d+) \(.*$#Uis', '$1', $data['campaign name']); |
| 47 | 53 | |
| 54 | + // Register the unsubscription on the email's stats | |
| 48 | 55 | if (in_array($action, ['unsubscribe', 'spam'])) { |
| 49 | 56 | acym_query('UPDATE #__acym_user_stat SET unsubscribe = unsubscribe + 1 WHERE user_id = '.intval($user->id).' AND mail_id = '.intval($mailId)); |
| 50 | 57 | acym_query('UPDATE #__acym_mail_stat SET unsubscribe_total = unsubscribe_total + 1 WHERE mail_id = '.intval($mailId)); |
| 51 | 58 | acym_query('UPDATE #__acym_user_has_list SET status = 0 WHERE user_id = '.intval($user->id)); |
| @@ -60,8 +67,9 @@ | ||
| 60 | 67 | acym_query('UPDATE #__acym_user_stat SET bounce = bounce + 1 WHERE user_id = '.intval($user->id).' AND mail_id = '.intval($mailId)); |
| 61 | 68 | } |
| 62 | 69 | } |
| 63 | 70 | |
| 71 | + // If found, disable the user and add the reason in their history | |
| 64 | 72 | $user->active = 0; |
| 65 | 73 | $userClass->save($user); |
| 66 | 74 | |
| 67 | 75 | $historyClass = new HistoryClass(); |