Skip to content

Firefly III: a personal finances manager

Fix login mail handing, #5173

James Cole66303f614b7a
diff --git a/app/Events/ActuallyLoggedIn.php b/app/Events/ActuallyLoggedIn.php
new file mode 100644
index 0000000000..0a664b1d1e
--- /dev/null
+++ b/app/Events/ActuallyLoggedIn.php
@@ -0,0 +1,44 @@
+<?php
+declare(strict_types=1);
+/*
+ * ActuallyLoggedIn.php
+ * Copyright (c) 2021 [email protected]
+ *
+ * This file is part of Firefly III (https://github.com/firefly-iii).
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+namespace FireflyIII\Events;
+
+use FireflyIII\User;
+use Illuminate\Queue\SerializesModels;
+
+/**
+ * Class ActuallyLoggedIn
+ */
+class ActuallyLoggedIn extends Event
+{
+ use SerializesModels;
+
+ public User $user;
+
+ /**
+ * @param User $user
+ */
+ public function __construct(User $user)
+ {
+ $this->user = $user;
+ }
+}
diff --git a/app/Handlers/Events/UserEventHandler.php b/app/Handlers/Events/UserEventHandler.php
index 35d5df3262..0022b1d559 100644
--- a/app/Handlers/Events/UserEventHandler.php
+++ b/app/Handlers/Events/UserEventHandler.php
@@ -25,6 +25,7 @@ namespace FireflyIII\Handlers\Events;
use Carbon\Carbon;
use Exception;
+use FireflyIII\Events\ActuallyLoggedIn;
use FireflyIII\Events\DetectedNewIPAddress;
use FireflyIII\Events\RegisteredUser;
use FireflyIII\Events\RequestedNewPassword;
@@ -317,11 +318,9 @@ class UserEventHandler
}
/**
- * @param Login $event
- *
- * @throws FireflyException
+ * @param ActuallyLoggedIn $event
*/
- public function storeUserIPAddress(Login $event): void
+ public function storeUserIPAddress(ActuallyLoggedIn $event): void
{
Log::debug('Now in storeUserIPAddress');
/** @var User $user */
@@ -337,7 +336,7 @@ class UserEventHandler
}
$inArray = false;
$ip = request()->ip();
- Log::debug(sprintf('User logging in from IP address %s using guard "%s"', $ip, $event->guard));
+ Log::debug(sprintf('User logging in from IP address %s', $ip));
// update array if in array
foreach ($preference as $index => $row) {
diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php
index 09cf875fe6..f59ea53d91 100644
--- a/app/Http/Controllers/Auth/LoginController.php
+++ b/app/Http/Controllers/Auth/LoginController.php
@@ -25,6 +25,7 @@ namespace FireflyIII\Http\Controllers\Auth;
use Adldap;
use Cookie;
use DB;
+use FireflyIII\Events\ActuallyLoggedIn;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Providers\RouteServiceProvider;
@@ -119,6 +120,10 @@ class LoginController extends Controller
// if you just logged in, it can't be that you have a valid 2FA cookie.
+ // send a custom login event because laravel will also fire a login event if a "remember me"-cookie
+ // restores the event.
+ event(new ActuallyLoggedIn($this->guard()->user()));
+
return $this->sendLoginResponse($request);
}
Log::warning('Login attempt failed.');
diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php
index 4eff73f510..84258e961c 100644
--- a/app/Providers/EventServiceProvider.php
+++ b/app/Providers/EventServiceProvider.php
@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Providers;
use Exception;
+use FireflyIII\Events\ActuallyLoggedIn;
use FireflyIII\Events\AdminRequestedTestMessage;
use FireflyIII\Events\DestroyedTransactionGroup;
use FireflyIII\Events\DetectedNewIPAddress;
@@ -74,6 +75,8 @@ class EventServiceProvider extends ServiceProvider
Login::class => [
'FireflyIII\Handlers\Events\UserEventHandler@checkSingleUserIsAdmin',
'FireflyIII\Handlers\Events\UserEventHandler@demoUserBackToEnglish',
+ ],
+ ActuallyLoggedIn::class => [
'FireflyIII\Handlers\Events\UserEventHandler@storeUserIPAddress',
],
DetectedNewIPAddress::class => [