Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Enabled MFA notifications #11544
James Cole8327a3d67040
diff --git a/app/Events/Security/User/UserHasEnabledMFA.php b/app/Events/Security/User/UserHasEnabledMFA.phpnew file mode 100644index 0000000000..6870978d7b--- /dev/null+++ b/app/Events/Security/User/UserHasEnabledMFA.php@@ -0,0 +1,45 @@+<?php+/*+ * UserHasEnabledMFA.php+ * Copyright (c) 2026 [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\Security\User;++use FireflyIII\Events\Event;+use FireflyIII\User;+use Illuminate\Contracts\Auth\Authenticatable;+use Illuminate\Queue\SerializesModels;+use InvalidArgumentException;++class UserHasEnabledMFA extends Event+{+ use SerializesModels;++ public User $user;++ public function __construct(Authenticatable|User|null $user)+ {+ if ($user instanceof User) {+ $this->user = $user;+ return;+ }+ throw new InvalidArgumentException('User must be an instance of User.');+ }+}+diff --git a/app/Handlers/Events/Security/MFAHandler.php b/app/Handlers/Events/Security/MFAHandler.phpindex 25d03ef12f..972af1223a 100644--- a/app/Handlers/Events/Security/MFAHandler.php+++ b/app/Handlers/Events/Security/MFAHandler.php@@ -25,13 +25,11 @@ declare(strict_types=1);namespace FireflyIII\Handlers\Events\Security;use Exception;-use FireflyIII\Events\Security\EnabledMFA;use FireflyIII\Events\Security\MFABackupFewLeft;use FireflyIII\Events\Security\MFABackupNoLeft;use FireflyIII\Events\Security\MFAManyFailedAttempts;use FireflyIII\Events\Security\MFANewBackupCodes;use FireflyIII\Events\Security\MFAUsedBackupCode;-use FireflyIII\Notifications\Security\EnabledMFANotification;use FireflyIII\Notifications\Security\MFABackupFewLeftNotification;use FireflyIII\Notifications\Security\MFABackupNoLeftNotification;use FireflyIII\Notifications\Security\MFAManyFailedAttemptsNotification;@@ -93,31 +91,6 @@ class MFAHandler}}- public function sendMFAEnabledMail(EnabledMFA $event): void- {- Log::debug(sprintf('Now in %s', __METHOD__));-- $user = $event->user;-- try {- Notification::send($user, new EnabledMFANotification($user));- } catch (Exception $e) {- $message = $e->getMessage();- if (str_contains($message, 'Bcc')) {- Log::warning('[Bcc] Could not send notification. Please validate your email settings, use the .env.example file as a guide.');-- return;- }- if (str_contains($message, 'RFC 2822')) {- Log::warning('[RFC] Could not send notification. Please validate your email settings, use the .env.example file as a guide.');-- return;- }- Log::error($e->getMessage());- Log::error($e->getTraceAsString());- }- }-public function sendMFAFailedAttemptsMail(MFAManyFailedAttempts $event): void{Log::debug(sprintf('Now in %s', __METHOD__));diff --git a/app/Http/Controllers/Profile/MfaController.php b/app/Http/Controllers/Profile/MfaController.phpindex 7076bf6e45..f97774d7f9 100644--- a/app/Http/Controllers/Profile/MfaController.php+++ b/app/Http/Controllers/Profile/MfaController.php@@ -25,9 +25,9 @@ declare(strict_types=1);namespace FireflyIII\Http\Controllers\Profile;use Carbon\Carbon;-use FireflyIII\Events\Security\EnabledMFA;use FireflyIII\Events\Security\MFANewBackupCodes;use FireflyIII\Events\Security\User\UserHasDisabledMFA;+use FireflyIII\Events\Security\User\UserHasEnabledMFA;use FireflyIII\Http\Controllers\Controller;use FireflyIII\Http\Middleware\IsDemoUser;use FireflyIII\Http\Requests\ExistingTokenFormRequest;@@ -279,7 +279,7 @@ class MfaController extends Controller// send user notification.Log::channel('audit')->info(sprintf('User "%s" has enabled MFA', $user->email));- event(new EnabledMFA($user));+ event(new UserHasEnabledMFA($user));return redirect(route('profile.mfa.backup-codes'));}diff --git a/app/Listeners/Security/User/NotifiesUserAboutEnabledMFA.php b/app/Listeners/Security/User/NotifiesUserAboutEnabledMFA.phpnew file mode 100644index 0000000000..8b5e9fe759--- /dev/null+++ b/app/Listeners/Security/User/NotifiesUserAboutEnabledMFA.php@@ -0,0 +1,55 @@+<?php+/*+ * NotifiesUserAboutEnabledMFA.php+ * Copyright (c) 2026 [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\Listeners\Security\User;++use Exception;+use FireflyIII\Events\Security\User\UserHasEnabledMFA;+use FireflyIII\Notifications\Security\EnabledMFANotification;+use Illuminate\Support\Facades\Log;+use Illuminate\Support\Facades\Notification;++class NotifiesUserAboutEnabledMFA+{+ public function handle(UserHasEnabledMFA $event): void {+ Log::debug(sprintf('Now in %s', __METHOD__));++ $user = $event->user;++ try {+ Notification::send($user, new EnabledMFANotification($user));+ } catch (Exception $e) {+ $message = $e->getMessage();+ if (str_contains($message, 'Bcc')) {+ Log::warning('[Bcc] Could not send notification. Please validate your email settings, use the .env.example file as a guide.');++ return;+ }+ if (str_contains($message, 'RFC 2822')) {+ Log::warning('[RFC] Could not send notification. Please validate your email settings, use the .env.example file as a guide.');++ return;+ }+ Log::error($e->getMessage());+ Log::error($e->getTraceAsString());+ }+ }+}diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.phpindex 2a9ca79366..f6f880bd5a 100644--- a/app/Providers/EventServiceProvider.php+++ b/app/Providers/EventServiceProvider.php@@ -35,7 +35,6 @@ use FireflyIII\Events\RequestedNewPassword;use FireflyIII\Events\RequestedReportOnJournals;use FireflyIII\Events\RequestedSendWebhookMessages;use FireflyIII\Events\RequestedVersionCheckStatus;-use FireflyIII\Events\Security\EnabledMFA;use FireflyIII\Events\Security\MFABackupFewLeft;use FireflyIII\Events\Security\MFABackupNoLeft;use FireflyIII\Events\Security\MFAManyFailedAttempts;@@ -182,9 +181,9 @@ class EventServiceProvider extends ServiceProvider// ],// security related- EnabledMFA::class => [- 'FireflyIII\Handlers\Events\Security\MFAHandler@sendMFAEnabledMail',- ],+ // EnabledMFA::class => [+ // 'FireflyIII\Handlers\Events\Security\MFAHandler@sendMFAEnabledMail',+ // ],// DisabledMFA::class => [// 'FireflyIII\Handlers\Events\Security\MFAHandler@sendMFADisabledMail',// ],