Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Clean up notifications
James Coleb3560ff52541
diff --git a/app/Events/Security/UserAttemptedLogin.php b/app/Events/Security/UserAttemptedLogin.phpnew file mode 100644index 0000000000..8457a5ecc3--- /dev/null+++ b/app/Events/Security/UserAttemptedLogin.php@@ -0,0 +1,42 @@+<?php+/*+ * UserAttemptedLogin.php+ * Copyright (c) 2024 [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/.+ */++declare(strict_types=1);++namespace FireflyIII\Events\Security;++use FireflyIII\Events\Event;+use Illuminate\Contracts\Auth\Authenticatable;+use Illuminate\Queue\SerializesModels;++class UserAttemptedLogin extends Event+{+ use SerializesModels;++ public User $user;++ public function __construct(null | Authenticatable | User $user)+ {+ if ($user instanceof User) {+ $this->user = $user;+ }+ }+}diff --git a/app/Handlers/Events/UserEventHandler.php b/app/Handlers/Events/UserEventHandler.phpindex aaac2ca8d5..91b63b4e18 100644--- a/app/Handlers/Events/UserEventHandler.php+++ b/app/Handlers/Events/UserEventHandler.php@@ -31,6 +31,7 @@ use FireflyIII\Events\Admin\InvitationCreated;use FireflyIII\Events\DetectedNewIPAddress;use FireflyIII\Events\RegisteredUser;use FireflyIII\Events\RequestedNewPassword;+use FireflyIII\Events\Security\UserAttemptedLogin;use FireflyIII\Events\Test\OwnerTestNotificationChannel;use FireflyIII\Events\Test\UserTestNotificationChannel;use FireflyIII\Events\UserChangedEmail;@@ -435,6 +436,26 @@ class UserEventHandler}}+ public function sendLoginAttemptNotification(UserAttemptedLogin $event): void {+ try {+ Notification::send($event->user, new UserFailedLoginAttempt($event->user));+ } catch (\Exception $e) { // @phpstan-ignore-line+ $message = $e->getMessage();+ if (str_contains($message, 'Bcc')) {+ app('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')) {+ app('log')->warning('[RFC] Could not send notification. Please validate your email settings, use the .env.example file as a guide.');++ return;+ }+ app('log')->error($e->getMessage());+ app('log')->error($e->getTraceAsString());+ }+ }+/*** Sends a test message to an administrator.*/diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.phpindex 9ec43cb780..6558e626de 100644--- a/app/Http/Controllers/Auth/LoginController.php+++ b/app/Http/Controllers/Auth/LoginController.php@@ -127,10 +127,14 @@ class LoginController extends Controller}app('log')->warning('Login attempt failed.');$username = (string) $request->get($this->username());- if (null === $this->repository->findByEmail($username)) {+ $user = $this->repository->findByEmail($username);+ if (null === $user) {// send event to owner.event(new UnknownUserAttemptedLogin($username));}+ if(null !== $user) {+ event(new UserAttemptedLogin($user));+ }// Copied directly from AuthenticatesUsers, but with logging added:// If the login attempt was unsuccessful we will increment the number of attemptsdiff --git a/app/Notifications/Admin/UnknownUserLoginAttempt.php b/app/Notifications/Admin/UnknownUserLoginAttempt.phpindex 4632a06e7e..6ee20a56e9 100644--- a/app/Notifications/Admin/UnknownUserLoginAttempt.php+++ b/app/Notifications/Admin/UnknownUserLoginAttempt.php@@ -39,21 +39,12 @@ class UnknownUserLoginAttempt extends Notificationuse Queueable;private string $address;- /**- * Create a new notification instance.- */public function __construct(string $address){$this->address = $address;}/**- * Get the array representation of the notification.- *- * @param mixed $notifiable- *- * @return array- ** @SuppressWarnings(PHPMD.UnusedFormalParameter)*/public function toArray(OwnerNotifiable $notifiable)@@ -63,8 +54,6 @@ class UnknownUserLoginAttempt extends Notification}/**- * Get the mail representation of the notification.- ** @SuppressWarnings(PHPMD.UnusedFormalParameter)*/public function toMail(OwnerNotifiable $notifiable): MailMessage@@ -76,8 +65,6 @@ class UnknownUserLoginAttempt extends Notification}/**- * Get the Slack representation of the notification.- ** @SuppressWarnings(PHPMD.UnusedFormalParameter)*/public function toSlack(OwnerNotifiable $notifiable): SlackMessage@@ -87,6 +74,9 @@ class UnknownUserLoginAttempt extends Notification);}+ /**+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)+ */public function toPushover(OwnerNotifiable $notifiable): PushoverMessage{return PushoverMessage::create((string) trans('email.unknown_user_message', ['address' => $this->address]))@@ -94,6 +84,9 @@ class UnknownUserLoginAttempt extends Notification;}+ /**+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)+ */public function toNtfy(OwnerNotifiable $notifiable): Message{$settings = ReturnsSettings::getSettings('ntfy', 'owner', null);@@ -106,8 +99,6 @@ class UnknownUserLoginAttempt extends Notification}/**- * Get the notification's delivery channels.- ** @SuppressWarnings(PHPMD.UnusedFormalParameter)*/public function via(OwnerNotifiable $notifiable)diff --git a/app/Notifications/Admin/UserInvitation.php b/app/Notifications/Admin/UserInvitation.phpindex 761d410f4c..a9d40ab9b0 100644--- a/app/Notifications/Admin/UserInvitation.php+++ b/app/Notifications/Admin/UserInvitation.php@@ -46,9 +46,7 @@ class UserInvitation extends Notificationprivate InvitedUser $invitee;private OwnerNotifiable $owner;- /**- * Create a new notification instance.- */+public function __construct(OwnerNotifiable $owner, InvitedUser $invitee){$this->invitee = $invitee;@@ -56,12 +54,6 @@ class UserInvitation extends Notification}/**- * Get the array representation of the notification.- *- * @param mixed $notifiable- *- * @return array- ** @SuppressWarnings(PHPMD.UnusedFormalParameter)*/public function toArray(OwnerNotifiable $notifiable)@@ -71,12 +63,6 @@ class UserInvitation extends Notification}/**- * Get the mail representation of the notification.- *- * @param mixed $notifiable- *- * @return MailMessage- ** @SuppressWarnings(PHPMD.UnusedFormalParameter)*/public function toMail(OwnerNotifiable $notifiable)@@ -88,12 +74,6 @@ class UserInvitation extends Notification}/**- * Get the Slack representation of the notification.- *- * @param mixed $notifiable- *- * @return SlackMessage- ** @SuppressWarnings(PHPMD.UnusedFormalParameter)*/public function toSlack(OwnerNotifiable $notifiable)@@ -102,7 +82,9 @@ class UserInvitation extends Notification(string) trans('email.invitation_created_body', ['email' => $this->invitee->user->email, 'invitee' => $this->invitee->email]));}-+ /**+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)+ */public function toPushover(OwnerNotifiable $notifiable): PushoverMessage{Log::debug('Now in toPushover() for UserInvitation');@@ -111,7 +93,9 @@ class UserInvitation extends Notification->title((string) trans('email.invitation_created_subject'));}-+ /**+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)+ */public function toNtfy(OwnerNotifiable $notifiable): Message{Log::debug('Now in toNtfy() for UserInvitation');@@ -125,12 +109,6 @@ class UserInvitation extends Notification}/**- * Get the notification's delivery channels.- *- * @param mixed $notifiable- *- * @return array- ** @SuppressWarnings(PHPMD.UnusedFormalParameter)*/public function via(OwnerNotifiable $notifiable)diff --git a/app/Notifications/Admin/UserRegistration.php b/app/Notifications/Admin/UserRegistration.phpindex 5745ca9e6d..e28e1ca239 100644--- a/app/Notifications/Admin/UserRegistration.php+++ b/app/Notifications/Admin/UserRegistration.php@@ -46,9 +46,7 @@ class UserRegistration extends Notificationprivate OwnerNotifiable $owner;private User $user;- /**- * Create a new notification instance.- */+public function __construct(OwnerNotifiable $owner, User $user){$this->user = $user;@@ -56,8 +54,6 @@ class UserRegistration extends Notification}/**- * Get the array representation of the notification.- ** @SuppressWarnings(PHPMD.UnusedFormalParameter)*/public function toArray(OwnerNotifiable $notifiable)@@ -67,12 +63,6 @@ class UserRegistration extends Notification}/**- * Get the mail representation of the notification.- *- * @param mixed $notifiable- *- * @return MailMessage- ** @SuppressWarnings(PHPMD.UnusedFormalParameter)*/public function toMail(OwnerNotifiable $notifiable)@@ -84,19 +74,15 @@ class UserRegistration extends Notification}/**- * Get the Slack representation of the notification.- *- * @param mixed $notifiable- *- * @return SlackMessage- ** @SuppressWarnings(PHPMD.UnusedFormalParameter)*/public function toSlack(OwnerNotifiable $notifiable){return (new SlackMessage())->content((string) trans('email.admin_new_user_registered', ['email' => $this->user->email, 'id' => $this->user->id]));}-+ /**+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)+ */public function toPushover(OwnerNotifiable $notifiable): PushoverMessage{Log::debug('Now in toPushover() for UserRegistration');@@ -105,7 +91,9 @@ class UserRegistration extends Notification->title((string) trans('email.registered_subject_admin'));}-+ /**+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)+ */public function toNtfy(OwnerNotifiable $notifiable): Message{Log::debug('Now in toNtfy() for (Admin) UserRegistration');@@ -119,12 +107,6 @@ class UserRegistration extends Notification}/**- * Get the notification's delivery channels.- *- * @param mixed $notifiable- *- * @return array- ** @SuppressWarnings(PHPMD.UnusedFormalParameter)*/public function via(OwnerNotifiable $notifiable)diff --git a/app/Notifications/Admin/VersionCheckResult.php b/app/Notifications/Admin/VersionCheckResult.phpindex 001c9c838f..68e28475d9 100644--- a/app/Notifications/Admin/VersionCheckResult.php+++ b/app/Notifications/Admin/VersionCheckResult.php@@ -44,21 +44,13 @@ class VersionCheckResult extends Notificationprivate string $message;- /**- * Create a new notification instance.- */+public function __construct(string $message){$this->message = $message;}/**- * Get the array representation of the notification.- *- * @param mixed $notifiable- *- * @return array- ** @SuppressWarnings(PHPMD.UnusedFormalParameter)*/public function toArray(OwnerNotifiable $notifiable)@@ -68,12 +60,6 @@ class VersionCheckResult extends Notification}/**- * Get the mail representation of the notification.- *- * @param mixed $notifiable- *- * @return MailMessage- ** @SuppressWarnings(PHPMD.UnusedFormalParameter)*/public function toMail(OwnerNotifiable $notifiable)@@ -85,12 +71,6 @@ class VersionCheckResult extends Notification}/**- * Get the Slack representation of the notification.- *- * @param mixed $notifiable- *- * @return SlackMessage- ** @SuppressWarnings(PHPMD.UnusedFormalParameter)*/public function toSlack(OwnerNotifiable $notifiable)@@ -101,7 +81,9 @@ class VersionCheckResult extends Notification});}-+ /**+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)+ */public function toPushover(OwnerNotifiable $notifiable): PushoverMessage{Log::debug('Now in toPushover() for VersionCheckResult');@@ -110,7 +92,9 @@ class VersionCheckResult extends Notification->title((string) trans('email.new_version_email_subject'));}-+ /**+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)+ */public function toNtfy(OwnerNotifiable $notifiable): Message{Log::debug('Now in toNtfy() for VersionCheckResult');@@ -124,12 +108,6 @@ class VersionCheckResult extends Notification}/**- * Get the notification's delivery channels.- *- * @param mixed $notifiable- *- * @return array- ** @SuppressWarnings(PHPMD.UnusedFormalParameter)*/public function via(OwnerNotifiable $notifiable)diff --git a/app/Notifications/Security/DisabledMFANotification.php b/app/Notifications/Security/DisabledMFANotification.phpindex f0efecf0cb..48dc9462a8 100644--- a/app/Notifications/Security/DisabledMFANotification.php+++ b/app/Notifications/Security/DisabledMFANotification.php@@ -42,21 +42,11 @@ class DisabledMFANotification extends Notificationprivate User $user;- /**- * Create a new notification instance.- */public function __construct(User $user){$this->user = $user;}-/**- * Get the array representation of the notification.- *- * @param User $notifiable- *- * @return array- ** @SuppressWarnings(PHPMD.UnusedFormalParameter)*/public function toArray(User $notifiable)@@ -66,12 +56,6 @@ class DisabledMFANotification extends Notification}/**- * Get the mail representation of the notification.- *- * @param User $notifiable- *- * @return MailMessage- ** @SuppressWarnings(PHPMD.UnusedFormalParameter)*/public function toMail(User $notifiable)@@ -80,14 +64,7 @@ class DisabledMFANotification extends Notificationreturn (new MailMessage())->markdown('emails.security.disabled-mfa', ['user' => $this->user])->subject($subject);}-/**- * Get the Slack representation of the notification.- *- * @param User $notifiable- *- * @return SlackMessage- ** @SuppressWarnings(PHPMD.UnusedFormalParameter)*/public function toSlack(User $notifiable)@@ -96,7 +73,9 @@ class DisabledMFANotification extends Notificationreturn (new SlackMessage())->content($message);}-+ /**+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)+ */public function toPushover(User $notifiable): PushoverMessage{Log::debug('Now in (user) toPushover()');@@ -104,6 +83,9 @@ class DisabledMFANotification extends Notificationreturn PushoverMessage::create((string) trans('email.disabled_mfa_slack', ['email' => $this->user->email]))->title((string)trans('email.disabled_mfa_subject'));}+ /**+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)+ */public function toNtfy(User $user): Message{$settings = ReturnsSettings::getSettings('ntfy', 'user', $user);@@ -116,12 +98,6 @@ class DisabledMFANotification extends Notification}/**- * Get the notification's delivery channels.- *- * @param User $notifiable- *- * @return array- ** @SuppressWarnings(PHPMD.UnusedFormalParameter)*/public function via(User $notifiable)diff --git a/app/Notifications/Security/EnabledMFANotification.php b/app/Notifications/Security/EnabledMFANotification.phpindex cfe5cf0e6d..fc927be354 100644--- a/app/Notifications/Security/EnabledMFANotification.php+++ b/app/Notifications/Security/EnabledMFANotification.php@@ -37,38 +37,20 @@ class EnabledMFANotification extends Notificationprivate User $user;- /**- * Create a new notification instance.- */+public function __construct(User $user){$this->user = $user;}- /**- * Get the array representation of the notification.- *- * @param mixed $notifiable- *- * @return array- *- * @SuppressWarnings(PHPMD.UnusedFormalParameter)- */+public function toArray($notifiable){return [];}- /**- * Get the mail representation of the notification.- *- * @param mixed $notifiable- *- * @return MailMessage- *- * @SuppressWarnings(PHPMD.UnusedFormalParameter)- */+public function toMail($notifiable){$subject = (string)trans('email.enabled_mfa_subject');@@ -76,15 +58,7 @@ class EnabledMFANotification extends Notificationreturn (new MailMessage())->markdown('emails.security.enabled-mfa', ['user' => $this->user])->subject($subject);}- /**- * Get the Slack representation of the notification.- *- * @param mixed $notifiable- *- * @return SlackMessage- *- * @SuppressWarnings(PHPMD.UnusedFormalParameter)- */+public function toSlack($notifiable){$message = (string)trans('email.enabled_mfa_slack', ['email' => $this->user->email]);@@ -92,15 +66,7 @@ class EnabledMFANotification extends Notificationreturn (new SlackMessage())->content($message);}- /**- * Get the notification's delivery channels.- *- * @param mixed $notifiable- *- * @return array- *- * @SuppressWarnings(PHPMD.UnusedFormalParameter)- */+public function via($notifiable){/** @var null|User $user */diff --git a/app/Notifications/Security/MFABackupFewLeftNotification.php b/app/Notifications/Security/MFABackupFewLeftNotification.phpindex d01925686f..c4e7209bb6 100644--- a/app/Notifications/Security/MFABackupFewLeftNotification.php+++ b/app/Notifications/Security/MFABackupFewLeftNotification.php@@ -38,39 +38,21 @@ class MFABackupFewLeftNotification extends Notificationprivate User $user;private int $count;- /**- * Create a new notification instance.- */+public function __construct(User $user, int $count){$this->user = $user;$this->count = $count;}- /**- * Get the array representation of the notification.- *- * @param mixed $notifiable- *- * @return array- *- * @SuppressWarnings(PHPMD.UnusedFormalParameter)- */+public function toArray($notifiable){return [];}- /**- * Get the mail representation of the notification.- *- * @param mixed $notifiable- *- * @return MailMessage- *- * @SuppressWarnings(PHPMD.UnusedFormalParameter)- */+public function toMail($notifiable){$subject = (string)trans('email.mfa_few_backups_left_subject', ['count' => $this->count]);@@ -78,15 +60,7 @@ class MFABackupFewLeftNotification extends Notificationreturn (new MailMessage())->markdown('emails.security.few-backup-codes', ['user' => $this->user, 'count' => $this->count])->subject($subject);}- /**- * Get the Slack representation of the notification.- *- * @param mixed $notifiable- *- * @return SlackMessage- *- * @SuppressWarnings(PHPMD.UnusedFormalParameter)- */+public function toSlack($notifiable){$message = (string)trans('email.mfa_few_backups_left_slack', ['email' => $this->user->email, 'count' => $this->count]);@@ -94,15 +68,7 @@ class MFABackupFewLeftNotification extends Notificationreturn (new SlackMessage())->content($message);}- /**- * Get the notification's delivery channels.- *- * @param mixed $notifiable- *- * @return array- *- * @SuppressWarnings(PHPMD.UnusedFormalParameter)- */+public function via($notifiable){/** @var null|User $user */diff --git a/app/Notifications/Security/MFABackupNoLeftNotification.php b/app/Notifications/Security/MFABackupNoLeftNotification.phpindex 91a98c1101..5e0199c079 100644--- a/app/Notifications/Security/MFABackupNoLeftNotification.php+++ b/app/Notifications/Security/MFABackupNoLeftNotification.php@@ -37,38 +37,20 @@ class MFABackupNoLeftNotification extends Notificationprivate User $user;- /**- * Create a new notification instance.- */+public function __construct(User $user){$this->user = $user;}- /**- * Get the array representation of the notification.- *- * @param mixed $notifiable- *- * @return array- *- * @SuppressWarnings(PHPMD.UnusedFormalParameter)- */+public function toArray($notifiable){return [];}- /**- * Get the mail representation of the notification.- *- * @param mixed $notifiable- *- * @return MailMessage- *- * @SuppressWarnings(PHPMD.UnusedFormalParameter)- */+public function toMail($notifiable){$subject = (string)trans('email.mfa_no_backups_left_subject');@@ -76,15 +58,7 @@ class MFABackupNoLeftNotification extends Notificationreturn (new MailMessage())->markdown('emails.security.no-backup-codes', ['user' => $this->user])->subject($subject);}- /**- * Get the Slack representation of the notification.- *- * @param mixed $notifiable- *- * @return SlackMessage- *- * @SuppressWarnings(PHPMD.UnusedFormalParameter)- */+public function toSlack($notifiable){$message = (string)trans('email.mfa_no_backups_left_slack', ['email' => $this->user->email]);@@ -92,15 +66,7 @@ class MFABackupNoLeftNotification extends Notificationreturn (new SlackMessage())->content($message);}- /**- * Get the notification's delivery channels.- *- * @param mixed $notifiable- *- * @return array- *- * @SuppressWarnings(PHPMD.UnusedFormalParameter)- */+public function via($notifiable){/** @var null|User $user */diff --git a/app/Notifications/Security/MFAManyFailedAttemptsNotification.php b/app/Notifications/Security/MFAManyFailedAttemptsNotification.phpindex b8926e58e8..d7d78863fe 100644--- a/app/Notifications/Security/MFAManyFailedAttemptsNotification.php+++ b/app/Notifications/Security/MFAManyFailedAttemptsNotification.php@@ -38,39 +38,21 @@ class MFAManyFailedAttemptsNotification extends Notificationprivate User $user;private int $count;- /**- * Create a new notification instance.- */+public function __construct(User $user, int $count){$this->user = $user;$this->count = $count;}- /**- * Get the array representation of the notification.- *- * @param mixed $notifiable- *- * @return array- *- * @SuppressWarnings(PHPMD.UnusedFormalParameter)- */+public function toArray($notifiable){return [];}- /**- * Get the mail representation of the notification.- *- * @param mixed $notifiable- *- * @return MailMessage- *- * @SuppressWarnings(PHPMD.UnusedFormalParameter)- */+public function toMail($notifiable){$subject = (string)trans('email.mfa_many_failed_subject', ['count' => $this->count]);@@ -78,15 +60,7 @@ class MFAManyFailedAttemptsNotification extends Notificationreturn (new MailMessage())->markdown('emails.security.many-failed-attempts', ['user' => $this->user, 'count' => $this->count])->subject($subject);}- /**- * Get the Slack representation of the notification.- *- * @param mixed $notifiable- *- * @return SlackMessage- *- * @SuppressWarnings(PHPMD.UnusedFormalParameter)- */+public function toSlack($notifiable){$message = (string)trans('email.mfa_many_failed_slack', ['email' => $this->user->email, 'count' => $this->count]);@@ -94,15 +68,7 @@ class MFAManyFailedAttemptsNotification extends Notificationreturn (new SlackMessage())->content($message);}- /**- * Get the notification's delivery channels.- *- * @param mixed $notifiable- *- * @return array- *- * @SuppressWarnings(PHPMD.UnusedFormalParameter)- */+public function via($notifiable){/** @var null|User $user */diff --git a/app/Notifications/Security/MFAUsedBackupCodeNotification.php b/app/Notifications/Security/MFAUsedBackupCodeNotification.phpindex 2179dd2357..5aac05099d 100644--- a/app/Notifications/Security/MFAUsedBackupCodeNotification.php+++ b/app/Notifications/Security/MFAUsedBackupCodeNotification.php@@ -37,38 +37,20 @@ class MFAUsedBackupCodeNotification extends Notificationprivate User $user;- /**- * Create a new notification instance.- */+public function __construct(User $user){$this->user = $user;}- /**- * Get the array representation of the notification.- *- * @param mixed $notifiable- *- * @return array- *- * @SuppressWarnings(PHPMD.UnusedFormalParameter)- */+public function toArray($notifiable){return [];}- /**- * Get the mail representation of the notification.- *- * @param mixed $notifiable- *- * @return MailMessage- *- * @SuppressWarnings(PHPMD.UnusedFormalParameter)- */+public function toMail($notifiable){$subject = (string)trans('email.used_backup_code_subject');@@ -76,15 +58,7 @@ class MFAUsedBackupCodeNotification extends Notificationreturn (new MailMessage())->markdown('emails.security.used-backup-code', ['user' => $this->user])->subject($subject);}- /**- * Get the Slack representation of the notification.- *- * @param mixed $notifiable- *- * @return SlackMessage- *- * @SuppressWarnings(PHPMD.UnusedFormalParameter)- */+public function toSlack($notifiable){$message = (string)trans('email.used_backup_code_slack', ['email' => $this->user->email]);@@ -92,15 +66,7 @@ class MFAUsedBackupCodeNotification extends Notificationreturn (new SlackMessage())->content($message);}- /**- * Get the notification's delivery channels.- *- * @param mixed $notifiable- *- * @return array- *- * @SuppressWarnings(PHPMD.UnusedFormalParameter)- */+public function via($notifiable){/** @var null|User $user */diff --git a/app/Notifications/Security/NewBackupCodesNotification.php b/app/Notifications/Security/NewBackupCodesNotification.phpindex eeaac3b0ac..8973242e02 100644--- a/app/Notifications/Security/NewBackupCodesNotification.php+++ b/app/Notifications/Security/NewBackupCodesNotification.php@@ -37,38 +37,20 @@ class NewBackupCodesNotification extends Notificationprivate User $user;- /**- * Create a new notification instance.- */+public function __construct(User $user){$this->user = $user;}- /**- * Get the array representation of the notification.- *- * @param mixed $notifiable- *- * @return array- *- * @SuppressWarnings(PHPMD.UnusedFormalParameter)- */+public function toArray($notifiable){return [];}- /**- * Get the mail representation of the notification.- *- * @param mixed $notifiable- *- * @return MailMessage- *- * @SuppressWarnings(PHPMD.UnusedFormalParameter)- */+public function toMail($notifiable){$subject = (string)trans('email.new_backup_codes_subject');@@ -76,15 +58,7 @@ class NewBackupCodesNotification extends Notificationreturn (new MailMessage())->markdown('emails.security.new-backup-codes', ['user' => $this->user])->subject($subject);}- /**- * Get the Slack representation of the notification.- *- * @param mixed $notifiable- *- * @return SlackMessage- *- * @SuppressWarnings(PHPMD.UnusedFormalParameter)- */+public function toSlack($notifiable){$message = (string)trans('email.new_backup_codes_slack', ['email' => $this->user->email]);@@ -92,15 +66,7 @@ class NewBackupCodesNotification extends Notificationreturn (new SlackMessage())->content($message);}- /**- * Get the notification's delivery channels.- *- * @param mixed $notifiable- *- * @return array- *- * @SuppressWarnings(PHPMD.UnusedFormalParameter)- */+public function via($notifiable){/** @var null|User $user */diff --git a/app/Notifications/Security/UserFailedLoginAttempt.php b/app/Notifications/Security/UserFailedLoginAttempt.phpnew file mode 100644index 0000000000..51a4462dc7--- /dev/null+++ b/app/Notifications/Security/UserFailedLoginAttempt.php@@ -0,0 +1,82 @@+<?php+/*+ * UserFailedLoginAttempt.php+ * Copyright (c) 2024 [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/.+ */++declare(strict_types=1);++namespace FireflyIII\Notifications\Security;++use FireflyIII\Support\Notifications\UrlValidator;+use Illuminate\Bus\Queueable;+use Illuminate\Notifications\Messages\MailMessage;+use Illuminate\Notifications\Messages\SlackMessage;+use Illuminate\Notifications\Notification;++class UserFailedLoginAttempt extends Notification+{+ use Queueable;++ private User $user;+++ public function __construct(User $user)+ {+ $this->user = $user;+ }+++ public function toArray($notifiable)+ {+ return [+ ];+ }+++ public function toMail($notifiable)+ {+ $subject = (string)trans('email.new_backup_codes_subject');++ return (new MailMessage())->markdown('emails.security.new-backup-codes', ['user' => $this->user])->subject($subject);+ }+++ public function toSlack($notifiable)+ {+ $message = (string)trans('email.new_backup_codes_slack', ['email' => $this->user->email]);++ return (new SlackMessage())->content($message);+ }+++ public function via($notifiable)+ {+ /** @var null|User $user */+ $user = auth()->user();+ $slackUrl = null === $user ? '' : app('preferences')->getForUser(auth()->user(), 'slack_webhook_url', '')->data;+ if (is_array($slackUrl)) {+ $slackUrl = '';+ }+ if (UrlValidator::isValidWebhookURL((string)$slackUrl)) {+ return ['mail', 'slack'];+ }++ return ['mail'];+ }+}diff --git a/app/Notifications/Test/OwnerTestNotificationEmail.php b/app/Notifications/Test/OwnerTestNotificationEmail.phpindex 9ac18ed14b..ed74b12537 100644--- a/app/Notifications/Test/OwnerTestNotificationEmail.php+++ b/app/Notifications/Test/OwnerTestNotificationEmail.php@@ -38,9 +38,7 @@ class OwnerTestNotificationEmail extends Notificationprivate OwnerNotifiable $owner;- /**- * Create a new notification instance.- */+public function __construct(OwnerNotifiable $owner){$this->owner = $owner;diff --git a/app/Notifications/Test/OwnerTestNotificationNtfy.php b/app/Notifications/Test/OwnerTestNotificationNtfy.phpindex d06594d542..d6ec326625 100644--- a/app/Notifications/Test/OwnerTestNotificationNtfy.php+++ b/app/Notifications/Test/OwnerTestNotificationNtfy.php@@ -42,9 +42,7 @@ class OwnerTestNotificationNtfy extends Notificationpublic OwnerNotifiable $owner;- /**- * Create a new notification instance.- */+public function __construct(OwnerNotifiable $owner){$this->owner = $owner;diff --git a/app/Notifications/Test/OwnerTestNotificationPushover.php b/app/Notifications/Test/OwnerTestNotificationPushover.phpindex 4d71f095ab..f5fdf1a032 100644--- a/app/Notifications/Test/OwnerTestNotificationPushover.php+++ b/app/Notifications/Test/OwnerTestNotificationPushover.php@@ -42,9 +42,7 @@ class OwnerTestNotificationPushover extends Notificationprivate OwnerNotifiable $owner;- /**- * Create a new notification instance.- */+public function __construct(OwnerNotifiable $owner){$this->owner = $owner;diff --git a/app/Notifications/Test/OwnerTestNotificationSlack.php b/app/Notifications/Test/OwnerTestNotificationSlack.phpindex 55dce8f62a..ea3dbab6d7 100644--- a/app/Notifications/Test/OwnerTestNotificationSlack.php+++ b/app/Notifications/Test/OwnerTestNotificationSlack.php@@ -40,9 +40,7 @@ class OwnerTestNotificationSlack extends Notificationprivate OwnerNotifiable $owner;- /**- * Create a new notification instance.- */+public function __construct(OwnerNotifiable $owner){$this->owner = $owner;diff --git a/app/Notifications/Test/UserTestNotificationEmail.php b/app/Notifications/Test/UserTestNotificationEmail.phpindex d617756849..25463f8789 100644--- a/app/Notifications/Test/UserTestNotificationEmail.php+++ b/app/Notifications/Test/UserTestNotificationEmail.php@@ -39,9 +39,7 @@ class UserTestNotificationEmail extends Notificationprivate User $user;- /**- * Create a new notification instance.- */+public function __construct(User $user){$this->user = $user;diff --git a/app/Notifications/Test/UserTestNotificationNtfy.php b/app/Notifications/Test/UserTestNotificationNtfy.phpindex 73877acd4a..5891701ed2 100644--- a/app/Notifications/Test/UserTestNotificationNtfy.php+++ b/app/Notifications/Test/UserTestNotificationNtfy.php@@ -42,9 +42,7 @@ class UserTestNotificationNtfy extends Notificationpublic User $user;- /**- * Create a new notification instance.- */+public function __construct(User $user){$this->user = $user;diff --git a/app/Notifications/Test/UserTestNotificationPushover.php b/app/Notifications/Test/UserTestNotificationPushover.phpindex 3acb2cf8aa..d694ae00ed 100644--- a/app/Notifications/Test/UserTestNotificationPushover.php+++ b/app/Notifications/Test/UserTestNotificationPushover.php@@ -43,9 +43,7 @@ class UserTestNotificationPushover extends Notificationprivate User $user;- /**- * Create a new notification instance.- */+public function __construct(User $user){$this->user = $user;diff --git a/app/Notifications/Test/UserTestNotificationSlack.php b/app/Notifications/Test/UserTestNotificationSlack.phpindex 759c06a318..0d935bccce 100644--- a/app/Notifications/Test/UserTestNotificationSlack.php+++ b/app/Notifications/Test/UserTestNotificationSlack.php@@ -40,9 +40,7 @@ class UserTestNotificationSlack extends Notificationprivate OwnerNotifiable $owner;- /**- * Create a new notification instance.- */+public function __construct(OwnerNotifiable $owner){$this->owner = $owner;diff --git a/app/Notifications/User/BillReminder.php b/app/Notifications/User/BillReminder.phpindex 36d93b84e6..5b2cb849b9 100644--- a/app/Notifications/User/BillReminder.php+++ b/app/Notifications/User/BillReminder.php@@ -43,9 +43,7 @@ class BillReminder extends Notificationprivate int $diff;private string $field;- /**- * Create a new notification instance.- */+public function __construct(Bill $bill, string $field, int $diff){$this->bill = $bill;@@ -53,30 +51,14 @@ class BillReminder extends Notification$this->diff = $diff;}- /**- * Get the array representation of the notification.- *- * @param mixed $notifiable- *- * @return array- *- * @SuppressWarnings(PHPMD.UnusedFormalParameter)- */+public function toArray($notifiable){return [];}- /**- * Get the mail representation of the notification.- *- * @param mixed $notifiable- *- * @return MailMessage- *- * @SuppressWarnings(PHPMD.UnusedFormalParameter)- */+public function toMail($notifiable){$subject = (string)trans(sprintf('email.bill_warning_subject_%s', $this->field), ['diff' => $this->diff, 'name' => $this->bill->name]);@@ -90,15 +72,7 @@ class BillReminder extends Notification;}- /**- * Get the Slack representation of the notification.- *- * @param mixed $notifiable- *- * @return SlackMessage- *- * @SuppressWarnings(PHPMD.UnusedFormalParameter)- */+public function toSlack($notifiable){$message = (string)trans(sprintf('email.bill_warning_subject_%s', $this->field), ['diff' => $this->diff, 'name' => $this->bill->name]);@@ -117,15 +91,7 @@ class BillReminder extends Notification;}- /**- * Get the notification's delivery channels.- *- * @param mixed $notifiable- *- * @return array- *- * @SuppressWarnings(PHPMD.UnusedFormalParameter)- */+public function via($notifiable){/** @var null|User $user */diff --git a/app/Notifications/User/NewAccessToken.php b/app/Notifications/User/NewAccessToken.phpindex b32192d089..126bc2f8c7 100644--- a/app/Notifications/User/NewAccessToken.php+++ b/app/Notifications/User/NewAccessToken.php@@ -38,35 +38,17 @@ class NewAccessToken extends Notification{use Queueable;- /**- * Create a new notification instance.- */+public function __construct() {}- /**- * Get the array representation of the notification.- *- * @param mixed $notifiable- *- * @return array- *- * @SuppressWarnings(PHPMD.UnusedFormalParameter)- */+public function toArray($notifiable){return [];}- /**- * Get the mail representation of the notification.- *- * @param mixed $notifiable- *- * @return MailMessage- *- * @SuppressWarnings(PHPMD.UnusedFormalParameter)- */+public function toMail($notifiable){return (new MailMessage())@@ -75,29 +57,13 @@ class NewAccessToken extends Notification;}- /**- * Get the Slack representation of the notification.- *- * @param mixed $notifiable- *- * @return SlackMessage- *- * @SuppressWarnings(PHPMD.UnusedFormalParameter)- */+public function toSlack($notifiable){return (new SlackMessage())->content((string)trans('email.access_token_created_body'));}- /**- * Get the notification's delivery channels.- *- * @param mixed $notifiable- *- * @return array- *- * @SuppressWarnings(PHPMD.UnusedFormalParameter)- */+public function via($notifiable){/** @var null|User $user */diff --git a/app/Notifications/User/RuleActionFailed.php b/app/Notifications/User/RuleActionFailed.phpindex 669d8b8e7b..35ea148b1e 100644--- a/app/Notifications/User/RuleActionFailed.php+++ b/app/Notifications/User/RuleActionFailed.php@@ -43,9 +43,7 @@ class RuleActionFailed extends Notificationprivate string $ruleLink;private string $ruleTitle;- /**- * Create a new notification instance.- */+public function __construct(array $params){[$mainMessage, $groupTitle, $groupLink, $ruleTitle, $ruleLink] = $params;@@ -56,30 +54,14 @@ class RuleActionFailed extends Notification$this->ruleLink = $ruleLink;}- /**- * Get the array representation of the notification.- *- * @param mixed $notifiable- *- * @return array- *- * @SuppressWarnings(PHPMD.UnusedFormalParameter)- */+public function toArray($notifiable){return [];}- /**- * Get the Slack representation of the notification.- *- * @param mixed $notifiable- *- * @return SlackMessage- *- * @SuppressWarnings(PHPMD.UnusedFormalParameter)- */+public function toSlack($notifiable){$groupTitle = $this->groupTitle;@@ -94,15 +76,7 @@ class RuleActionFailed extends Notification});}- /**- * Get the notification's delivery channels.- *- * @param mixed $notifiable- *- * @return array- *- * @SuppressWarnings(PHPMD.UnusedFormalParameter)- */+public function via($notifiable){/** @var null|User $user */diff --git a/app/Notifications/User/TransactionCreation.php b/app/Notifications/User/TransactionCreation.phpindex fcf9f95fc0..61e2626d8a 100644--- a/app/Notifications/User/TransactionCreation.php+++ b/app/Notifications/User/TransactionCreation.php@@ -37,38 +37,20 @@ class TransactionCreation extends Notificationprivate array $collection;- /**- * Create a new notification instance.- */+public function __construct(array $collection){$this->collection = $collection;}- /**- * Get the array representation of the notification.- *- * @param mixed $notifiable- *- * @return array- *- * @SuppressWarnings(PHPMD.UnusedFormalParameter)- */+public function toArray($notifiable){return [];}- /**- * Get the mail representation of the notification.- *- * @param mixed $notifiable- *- * @return MailMessage- *- * @SuppressWarnings(PHPMD.UnusedFormalParameter)- */+public function toMail($notifiable){return (new MailMessage())@@ -77,15 +59,7 @@ class TransactionCreation extends Notification;}- /**- * Get the notification's delivery channels.- *- * @param mixed $notifiable- *- * @return array- *- * @SuppressWarnings(PHPMD.UnusedFormalParameter)- */+public function via($notifiable){return ['mail'];diff --git a/app/Notifications/User/UserLogin.php b/app/Notifications/User/UserLogin.phpindex e7fc4e8a53..3107748de0 100644--- a/app/Notifications/User/UserLogin.php+++ b/app/Notifications/User/UserLogin.php@@ -41,38 +41,20 @@ class UserLogin extends Notificationprivate string $ip;- /**- * Create a new notification instance.- */+public function __construct(string $ip){$this->ip = $ip;}- /**- * Get the array representation of the notification.- *- * @param mixed $notifiable- *- * @return array- *- * @SuppressWarnings(PHPMD.UnusedFormalParameter)- */+public function toArray($notifiable){return [];}- /**- * Get the mail representation of the notification.- *- * @param mixed $notifiable- *- * @return MailMessage- *- * @SuppressWarnings(PHPMD.UnusedFormalParameter)- */+public function toMail($notifiable){$time = now(config('app.timezone'))->isoFormat((string)trans('config.date_time_js'));@@ -94,15 +76,7 @@ class UserLogin extends Notification;}- /**- * Get the Slack representation of the notification.- *- * @param mixed $notifiable- *- * @return SlackMessage- *- * @SuppressWarnings(PHPMD.UnusedFormalParameter)- */+public function toSlack($notifiable){$host = '';@@ -120,15 +94,7 @@ class UserLogin extends Notificationreturn (new SlackMessage())->content((string)trans('email.slack_login_from_new_ip', ['host' => $host, 'ip' => $this->ip]));}- /**- * Get the notification's delivery channels.- *- * @param mixed $notifiable- *- * @return array- *- * @SuppressWarnings(PHPMD.UnusedFormalParameter)- */+public function via($notifiable){/** @var null|User $user */diff --git a/app/Notifications/User/UserNewPassword.php b/app/Notifications/User/UserNewPassword.phpindex e4090984d5..e75861add3 100644--- a/app/Notifications/User/UserNewPassword.php+++ b/app/Notifications/User/UserNewPassword.php@@ -37,38 +37,20 @@ class UserNewPassword extends Notificationprivate string $url;- /**- * Create a new notification instance.- */+public function __construct(string $url){$this->url = $url;}- /**- * Get the array representation of the notification.- *- * @param mixed $notifiable- *- * @return array- *- * @SuppressWarnings(PHPMD.UnusedFormalParameter)- */+public function toArray($notifiable){return [];}- /**- * Get the mail representation of the notification.- *- * @param mixed $notifiable- *- * @return MailMessage- *- * @SuppressWarnings(PHPMD.UnusedFormalParameter)- */+public function toMail($notifiable){return (new MailMessage())@@ -77,15 +59,7 @@ class UserNewPassword extends Notification;}- /**- * Get the notification's delivery channels.- *- * @param mixed $notifiable- *- * @return array- *- * @SuppressWarnings(PHPMD.UnusedFormalParameter)- */+public function via($notifiable){return ['mail'];diff --git a/app/Notifications/User/UserRegistration.php b/app/Notifications/User/UserRegistration.phpindex 50aae568a3..bde33969f6 100644--- a/app/Notifications/User/UserRegistration.php+++ b/app/Notifications/User/UserRegistration.php@@ -35,35 +35,17 @@ class UserRegistration extends Notification{use Queueable;- /**- * Create a new notification instance.- */+public function __construct() {}- /**- * Get the array representation of the notification.- *- * @param mixed $notifiable- *- * @return array- *- * @SuppressWarnings(PHPMD.UnusedFormalParameter)- */+public function toArray($notifiable){return [];}- /**- * Get the mail representation of the notification.- *- * @param mixed $notifiable- *- * @return MailMessage- *- * @SuppressWarnings(PHPMD.UnusedFormalParameter)- */+public function toMail($notifiable){return (new MailMessage())@@ -72,15 +54,7 @@ class UserRegistration extends Notification;}- /**- * Get the notification's delivery channels.- *- * @param mixed $notifiable- *- * @return array- *- * @SuppressWarnings(PHPMD.UnusedFormalParameter)- */+public function via($notifiable){return ['mail'];diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.phpindex d6931d1da6..9ce9cef6b0 100644--- a/app/Providers/EventServiceProvider.php+++ b/app/Providers/EventServiceProvider.php@@ -47,6 +47,7 @@ use FireflyIII\Events\Security\MFAManyFailedAttempts;use FireflyIII\Events\Security\MFANewBackupCodes;use FireflyIII\Events\Security\MFAUsedBackupCode;use FireflyIII\Events\Security\UnknownUserAttemptedLogin;+use FireflyIII\Events\Security\UserAttemptedLogin;use FireflyIII\Events\StoredAccount;use FireflyIII\Events\StoredTransactionGroup;use FireflyIII\Events\Test\OwnerTestNotificationChannel;@@ -109,6 +110,9 @@ class EventServiceProvider extends ServiceProvider'FireflyIII\Handlers\Events\UserEventHandler@createGroupMembership','FireflyIII\Handlers\Events\UserEventHandler@createExchangeRates',],+ UserAttemptedLogin::class => [+ 'FireflyIII\Handlers\Events\UserEventHandler@sendLoginAttemptNotification',+ ],// is a User related event.Login::class => ['FireflyIII\Handlers\Events\UserEventHandler@checkSingleUserIsAdmin',