From 9b83974bff6db17ab87a967d73c0d808fb12b2ad Mon Sep 17 00:00:00 2001 From: James Cole Date: Fri, 24 Jul 2015 13:17:47 +0200 Subject: [PATCH] Improve the cron controller. Force blocked users to logout. --- app/Http/Controllers/CronController.php | 22 +++++++++++----------- app/Http/Middleware/Authenticate.php | 5 +++++ 2 files changed, 16 insertions(+), 11 deletions(-) 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 "
\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);