The Sendgrid cron does not belong in Firefly.

This commit is contained in:
James Cole 2016-01-06 15:20:21 +01:00
parent 8526907f50
commit 6f2b1a6a76
3 changed files with 0 additions and 98 deletions

View File

@ -27,7 +27,4 @@ ANALYTICS_ID=
RUNCLEANUP=true
SITE_OWNER=mail@example.com
SENDGRID_USERNAME=
SENDGRID_PASSWORD=
BLOCKED_DOMAINS=

View File

@ -1,94 +0,0 @@
<?php
namespace FireflyIII\Http\Controllers;
use FireflyIII\User;
/**
* Class WebhookController
*
* @package FireflyIII\Http\Controllers
*/
class CronController extends Controller
{
/** @var array */
protected $set = [];
/** @var array */
protected $parameters = [];
/**
* CronController constructor.
*/
public function __construct()
{
parent::__construct();
$this->set = [
'blocks' => 'https://api.sendgrid.com/api/blocks.get.json',
'bounces' => 'https://api.sendgrid.com/api/bounces.get.json',
'invalids' => 'https://api.sendgrid.com/api/invalidemails.get.json',
];
$this->parameters = [
'api_user' => env('SENDGRID_USERNAME'),
'api_key' => env('SENDGRID_PASSWORD'),
'date' => 1,
'days' => 7
];
}
/**
* Firefly doesn't have anything that should be in the a cron job, except maybe this one, and it's fairly exceptional.
*
* If you use SendGrid like I do, you can detect bounces and thereby check if users gave an invalid address. If they did,
* it's easy to block them and change their password. Optionally, you could notify yourself about it and send them a message.
*
* But thats something not supported right now.
*/
public function sendgrid()
{
if (strlen(env('SENDGRID_USERNAME')) > 0 && strlen(env('SENDGRID_PASSWORD')) > 0) {
echo '<pre>';
foreach ($this->set as $name => $url) {
$data = json_decode(file_get_contents($url . '?' . http_build_query($this->parameters)));
$this->processResult($name, $data);
}
echo 'Done!' . "\n";
} else {
echo 'Please fill in SendGrid details.';
}
}
/**
* @param string $name
* @param array $data
*/
protected function processResult($name, array $data)
{
if (is_array($data)) {
echo 'Found ' . count($data) . ' entries in the SendGrid ' . $name . ' list.' . "\n";
foreach ($data as $entry) {
$address = $entry->email;
$user = User::where('email', $address)->where('blocked', 0)->first();
if (!is_null($user)) {
echo 'Found a user: ' . $address . ', who is now blocked.' . "\n";
$user->blocked = 1;
$user->blocked_code = 'bounced';
$user->password = 'bounced';
$user->save();
} else {
echo 'Found no user: ' . $address . ', did nothing.' . "\n";
}
}
}
}
}

View File

@ -264,7 +264,6 @@ Route::bind(
* Auth\AuthController
*/
Route::get('/register', ['uses' => 'Auth\AuthController@getRegister', 'as' => 'register']);
Route::get('/cron/sendgrid', ['uses' => 'CronController@sendgrid']);
Route::controllers(
[