1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-08 12:12:48 +01:00

Support setting subscription secret

This commit is contained in:
Hillel Coren 2017-12-26 16:42:46 +02:00
parent 4777586dbe
commit 937652390b
4 changed files with 35 additions and 30 deletions

View File

@ -1,4 +1,3 @@
<?php <?php
namespace App\Events; namespace App\Events;

View File

@ -911,32 +911,6 @@ class Utils
} }
} }
public static function notifyZapier($subscription, $data)
{
$curl = curl_init();
$jsonEncodedData = json_encode($data);
$opts = [
CURLOPT_URL => $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) public static function getApiHeaders($count = 0)
{ {
return [ return [

View File

@ -257,7 +257,39 @@ class SubscriptionListener
} }
foreach ($subscriptions as $subscription) { 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();
}
}
} }

View File

@ -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. 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 Google Map
"""""""""" """"""""""