diff --git a/app/Events/ClientWasCreated.php b/app/Events/ClientWasCreated.php index 8a4c9fc1a6..1fa399469d 100644 --- a/app/Events/ClientWasCreated.php +++ b/app/Events/ClientWasCreated.php @@ -1,4 +1,3 @@ - $subscription->target_url, - CURLOPT_RETURNTRANSFER => true, - CURLOPT_CUSTOMREQUEST => 'POST', - CURLOPT_POST => 1, - CURLOPT_POSTFIELDS => $jsonEncodedData, - CURLOPT_HTTPHEADER => ['Content-Type: application/json', 'Content-Length: '.strlen($jsonEncodedData)], - ]; - - curl_setopt_array($curl, $opts); - - $result = curl_exec($curl); - $status = curl_getinfo($curl, CURLINFO_HTTP_CODE); - - curl_close($curl); - - if ($status == 410) { - $subscription->delete(); - } - } - public static function getApiHeaders($count = 0) { return [ diff --git a/app/Listeners/SubscriptionListener.php b/app/Listeners/SubscriptionListener.php index c5fac2b6c1..df0928e354 100644 --- a/app/Listeners/SubscriptionListener.php +++ b/app/Listeners/SubscriptionListener.php @@ -257,7 +257,39 @@ class SubscriptionListener } foreach ($subscriptions as $subscription) { - Utils::notifyZapier($subscription, $data); + self::notifySubscription($subscription, $data); } } + + private static function notifySubscription($subscription, $data) + { + $curl = curl_init(); + $jsonEncodedData = json_encode($data); + $url = $subscription->target_url; + + if (! Utils::isNinja() && $secret = env('SUBSCRIPTION_SECRET')) { + $url .= '?secret=' . $secret; + } + + $opts = [ + CURLOPT_URL => $url, + CURLOPT_RETURNTRANSFER => true, + CURLOPT_CUSTOMREQUEST => 'POST', + CURLOPT_POST => 1, + CURLOPT_POSTFIELDS => $jsonEncodedData, + CURLOPT_HTTPHEADER => ['Content-Type: application/json', 'Content-Length: '.strlen($jsonEncodedData)], + ]; + + curl_setopt_array($curl, $opts); + + $result = curl_exec($curl); + $status = curl_getinfo($curl, CURLINFO_HTTP_CODE); + + curl_close($curl); + + if ($status == 410) { + $subscription->delete(); + } + } + } diff --git a/docs/configure.rst b/docs/configure.rst index 7e8c1273ff..413b51321a 100644 --- a/docs/configure.rst +++ b/docs/configure.rst @@ -99,9 +99,9 @@ Security To require a password to update the app add ``UPDATE_SECRET=random_value`` to the .env file and then use /update?secret=random_value to update. -By default the app clears the session when the browser is closed and automatically logs the user out after 8 hours. +By default the app clears the session when the browser is closed and automatically logs the user out after 8 hours. This can be modified by setting ``REMEMBER_ME_ENABLED`` and ``AUTO_LOGOUT_SECONDS`` in the .env file. -This can be modified by setting ``REMEMBER_ME_ENABLED`` and ``AUTO_LOGOUT_SECONDS`` in the .env file. +To include a secret when notifying subscriptions add ``SUBSCRIPTION_SECRET=random_value`` to the .env file. Google Map """"""""""