2015-07-22 12:09:17 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace FireflyIII\Http\Controllers;
|
|
|
|
|
|
|
|
use FireflyIII\User;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class WebhookController
|
|
|
|
*
|
|
|
|
* @package FireflyIII\Http\Controllers
|
|
|
|
*/
|
|
|
|
class CronController extends Controller
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
2015-07-24 06:17:47 -05:00
|
|
|
* Firefly doesn't have anything that should be in the a cron job, except maybe this one, and it's fairly exceptional.
|
2015-07-22 12:09:17 -05:00
|
|
|
*
|
2015-07-24 06:17:47 -05:00
|
|
|
* 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.
|
2015-07-24 06:20:09 -05:00
|
|
|
*
|
|
|
|
* But thats something not supported right now.
|
2015-07-22 12:09:17 -05:00
|
|
|
*/
|
|
|
|
public function sendgrid()
|
|
|
|
{
|
|
|
|
|
2015-07-24 06:23:02 -05:00
|
|
|
if (strlen(env('SENDGRID_USERNAME')) > 0 && strlen(env('SENDGRID_PASSWORD')) > 0) {
|
|
|
|
|
2015-08-19 12:21:39 -05:00
|
|
|
$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',
|
|
|
|
|
2015-07-24 06:23:02 -05:00
|
|
|
];
|
2015-08-19 12:21:39 -05:00
|
|
|
echo '<pre>';
|
|
|
|
foreach ($set as $name => $URL) {
|
|
|
|
|
|
|
|
|
|
|
|
$parameters = [
|
|
|
|
'api_user' => env('SENDGRID_USERNAME'),
|
|
|
|
'api_key' => env('SENDGRID_PASSWORD'),
|
|
|
|
'date' => 1,
|
|
|
|
'days' => 7
|
|
|
|
];
|
|
|
|
$fullURL = $URL . '?' . http_build_query($parameters);
|
|
|
|
$data = json_decode(file_get_contents($fullURL));
|
2015-07-24 06:23:02 -05:00
|
|
|
|
2015-08-19 12:21:39 -05:00
|
|
|
/*
|
|
|
|
* Loop the result, if any.
|
|
|
|
*/
|
|
|
|
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";
|
|
|
|
}
|
2015-07-24 06:23:02 -05:00
|
|
|
}
|
2015-07-22 12:35:39 -05:00
|
|
|
}
|
2015-07-22 12:09:17 -05:00
|
|
|
}
|
2015-07-24 06:26:42 -05:00
|
|
|
echo 'Done!' . "\n";
|
|
|
|
} else {
|
|
|
|
echo 'Please fill in SendGrid details.';
|
2015-07-22 12:09:17 -05:00
|
|
|
}
|
2015-07-24 06:26:42 -05:00
|
|
|
|
2015-07-22 12:09:17 -05:00
|
|
|
}
|
|
|
|
|
2015-07-26 00:42:34 -05:00
|
|
|
}
|