mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Improve the cron controller. Force blocked users to logout.
This commit is contained in:
parent
3c68c99bd5
commit
9b83974bff
@ -2,7 +2,6 @@
|
||||
|
||||
namespace FireflyIII\Http\Controllers;
|
||||
|
||||
use FireflyIII\Models\Preference;
|
||||
use FireflyIII\User;
|
||||
|
||||
/**
|
||||
@ -14,7 +13,10 @@ class CronController extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public function sendgrid()
|
||||
{
|
||||
@ -28,21 +30,19 @@ class CronController extends Controller
|
||||
];
|
||||
$fullURL = $URL . '?' . http_build_query($parameters);
|
||||
$data = json_decode(file_get_contents($fullURL));
|
||||
$users = [];
|
||||
echo "<pre>\n";
|
||||
// loop the result, if any.
|
||||
|
||||
var_dump($data);
|
||||
/*
|
||||
* Loop the result, if any.
|
||||
*/
|
||||
if (is_array($data)) {
|
||||
foreach ($data as $entry) {
|
||||
$address = $entry->email;
|
||||
$user = User::where('email', $address)->first();
|
||||
if (!is_null($user)) {
|
||||
$users[] = $user;
|
||||
echo "Blocked " . $user->email . " because a message bounced.\n";
|
||||
|
||||
// create preference:
|
||||
$preference = Preference::firstOrCreate(['user_id' => $user->id, 'name' => 'bounce']);
|
||||
$preference->data = $entry->reason;
|
||||
$preference->save();
|
||||
$user->blocked = 1;
|
||||
$user->password = 'bounced';
|
||||
$user->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -52,6 +52,11 @@ class Authenticate
|
||||
return redirect()->guest('auth/login');
|
||||
}
|
||||
}
|
||||
|
||||
if (intval($this->auth->user()->blocked) == 1) {
|
||||
return redirect()->route('logout');
|
||||
}
|
||||
|
||||
// if logged in, set user language:
|
||||
$pref = Preferences::get('language', 'en');
|
||||
App::setLocale($pref->data);
|
||||
|
Loading…
Reference in New Issue
Block a user