Skip to content

Firefly III: a personal finances manager

Improve the cron controller. Force blocked users to logout.

James Cole9b83974bff6d
diff --git a/app/Http/Controllers/CronController.php b/app/Http/Controllers/CronController.php
index 0e29913dd5..69f5e3f87e 100644
--- a/app/Http/Controllers/CronController.php
+++ b/app/Http/Controllers/CronController.php
@@ -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();
}
}
}
diff --git a/app/Http/Middleware/Authenticate.php b/app/Http/Middleware/Authenticate.php
index e83a32aefb..23026e7bde 100644
--- a/app/Http/Middleware/Authenticate.php
+++ b/app/Http/Middleware/Authenticate.php
@@ -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);