Improve the cron controller. Force blocked users to logout.

This commit is contained in:
James Cole 2015-07-24 13:17:47 +02:00
parent 3c68c99bd5
commit 9b83974bff
2 changed files with 16 additions and 11 deletions

View File

@ -2,7 +2,6 @@
namespace FireflyIII\Http\Controllers; namespace FireflyIII\Http\Controllers;
use FireflyIII\Models\Preference;
use FireflyIII\User; 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() public function sendgrid()
{ {
@ -28,21 +30,19 @@ class CronController extends Controller
]; ];
$fullURL = $URL . '?' . http_build_query($parameters); $fullURL = $URL . '?' . http_build_query($parameters);
$data = json_decode(file_get_contents($fullURL)); $data = json_decode(file_get_contents($fullURL));
$users = [];
echo "<pre>\n"; var_dump($data);
// loop the result, if any. /*
* Loop the result, if any.
*/
if (is_array($data)) { if (is_array($data)) {
foreach ($data as $entry) { foreach ($data as $entry) {
$address = $entry->email; $address = $entry->email;
$user = User::where('email', $address)->first(); $user = User::where('email', $address)->first();
if (!is_null($user)) { if (!is_null($user)) {
$users[] = $user; $user->blocked = 1;
echo "Blocked " . $user->email . " because a message bounced.\n"; $user->password = 'bounced';
$user->save();
// create preference:
$preference = Preference::firstOrCreate(['user_id' => $user->id, 'name' => 'bounce']);
$preference->data = $entry->reason;
$preference->save();
} }
} }
} }

View File

@ -52,6 +52,11 @@ class Authenticate
return redirect()->guest('auth/login'); return redirect()->guest('auth/login');
} }
} }
if (intval($this->auth->user()->blocked) == 1) {
return redirect()->route('logout');
}
// if logged in, set user language: // if logged in, set user language:
$pref = Preferences::get('language', 'en'); $pref = Preferences::get('language', 'en');
App::setLocale($pref->data); App::setLocale($pref->data);