mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Clean up and fix notifications.
This commit is contained in:
parent
5f1502eea7
commit
5520992861
@ -24,6 +24,7 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Events\Security;
|
||||
|
||||
use FireflyIII\Events\Event;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Contracts\Auth\Authenticatable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
|
@ -43,6 +43,7 @@ use FireflyIII\Models\GroupMembership;
|
||||
use FireflyIII\Models\UserGroup;
|
||||
use FireflyIII\Models\UserRole;
|
||||
use FireflyIII\Notifications\Admin\UserRegistration as AdminRegistrationNotification;
|
||||
use FireflyIII\Notifications\Security\UserFailedLoginAttempt;
|
||||
use FireflyIII\Notifications\Test\OwnerTestNotificationEmail;
|
||||
use FireflyIII\Notifications\Test\OwnerTestNotificationNtfy;
|
||||
use FireflyIII\Notifications\Test\OwnerTestNotificationPushover;
|
||||
|
@ -26,6 +26,7 @@ namespace FireflyIII\Http\Controllers\Auth;
|
||||
use Cookie;
|
||||
use FireflyIII\Events\ActuallyLoggedIn;
|
||||
use FireflyIII\Events\Security\UnknownUserAttemptedLogin;
|
||||
use FireflyIII\Events\Security\UserAttemptedLogin;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Providers\RouteServiceProvider;
|
||||
|
@ -103,7 +103,7 @@ class UserInvitation extends Notification
|
||||
*/
|
||||
public function toSlack(OwnerNotifiable $notifiable)
|
||||
{
|
||||
return (new SlackMessage())->content(
|
||||
return new SlackMessage()->content(
|
||||
(string) trans('email.invitation_created_body', ['email' => $this->invitee->user->email, 'invitee' => $this->invitee->email])
|
||||
);
|
||||
}
|
||||
|
@ -103,7 +103,7 @@ class UserRegistration extends Notification
|
||||
*/
|
||||
public function toSlack(OwnerNotifiable $notifiable)
|
||||
{
|
||||
return (new SlackMessage())->content((string) trans('email.admin_new_user_registered', ['email' => $this->user->email, 'id' => $this->user->id]));
|
||||
return new SlackMessage()->content((string) trans('email.admin_new_user_registered', ['email' => $this->user->email, 'id' => $this->user->id]));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -100,7 +100,7 @@ class VersionCheckResult extends Notification
|
||||
*/
|
||||
public function toSlack(OwnerNotifiable $notifiable)
|
||||
{
|
||||
return (new SlackMessage())->content($this->message)
|
||||
return new SlackMessage()->content($this->message)
|
||||
->attachment(static function ($attachment): void {
|
||||
$attachment->title('Firefly III @ GitHub', 'https://github.com/firefly-iii/firefly-iii/releases');
|
||||
});
|
||||
|
@ -65,12 +65,9 @@ class DisabledMFANotification extends Notification
|
||||
return (new MailMessage())->markdown('emails.security.disabled-mfa', ['user' => $this->user])->subject($subject);
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function toNtfy(User $user): Message
|
||||
public function toNtfy(User $notifiable): Message
|
||||
{
|
||||
$settings = ReturnsSettings::getSettings('ntfy', 'user', $user);
|
||||
$settings = ReturnsSettings::getSettings('ntfy', 'user', $notifiable);
|
||||
$message = new Message();
|
||||
$message->topic($settings['ntfy_topic']);
|
||||
$message->title((string) trans('email.disabled_mfa_subject'));
|
||||
@ -84,8 +81,6 @@ class DisabledMFANotification extends Notification
|
||||
*/
|
||||
public function toPushover(User $notifiable): PushoverMessage
|
||||
{
|
||||
Log::debug('Now in (user) toPushover()');
|
||||
|
||||
return PushoverMessage::create((string) trans('email.disabled_mfa_slack', ['email' => $this->user->email]))
|
||||
->title((string) trans('email.disabled_mfa_subject'));
|
||||
}
|
||||
@ -97,7 +92,7 @@ class DisabledMFANotification extends Notification
|
||||
{
|
||||
$message = (string) trans('email.disabled_mfa_slack', ['email' => $this->user->email]);
|
||||
|
||||
return (new SlackMessage())->content($message);
|
||||
return new SlackMessage()->content($message);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -25,11 +25,14 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Notifications\Security;
|
||||
|
||||
use FireflyIII\Notifications\ReturnsAvailableChannels;
|
||||
use FireflyIII\Notifications\ReturnsSettings;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Notifications\Messages\SlackMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
use NotificationChannels\Pushover\PushoverMessage;
|
||||
use Ntfy\Message;
|
||||
|
||||
class EnabledMFANotification extends Notification
|
||||
{
|
||||
@ -62,6 +65,26 @@ class EnabledMFANotification extends Notification
|
||||
return (new MailMessage())->markdown('emails.security.enabled-mfa', ['user' => $this->user])->subject($subject);
|
||||
}
|
||||
|
||||
public function toNtfy(User $notifiable): Message
|
||||
{
|
||||
$settings = ReturnsSettings::getSettings('ntfy', 'user', $notifiable);
|
||||
$message = new Message();
|
||||
$message->topic($settings['ntfy_topic']);
|
||||
$message->title((string) trans('email.enabled_mfa_subject'));
|
||||
$message->body((string) trans('email.enabled_mfa_slack', ['email' => $this->user->email]));
|
||||
|
||||
return $message;
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function toPushover(User $notifiable): PushoverMessage
|
||||
{
|
||||
return PushoverMessage::create((string) trans('email.enabled_mfa_slack', ['email' => $this->user->email]))
|
||||
->title((string) trans('email.enabled_mfa_subject'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
@ -69,7 +92,7 @@ class EnabledMFANotification extends Notification
|
||||
{
|
||||
$message = (string) trans('email.enabled_mfa_slack', ['email' => $this->user->email]);
|
||||
|
||||
return (new SlackMessage())->content($message);
|
||||
return new SlackMessage()->content($message);
|
||||
}
|
||||
|
||||
|
||||
|
@ -25,11 +25,14 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Notifications\Security;
|
||||
|
||||
use FireflyIII\Notifications\ReturnsAvailableChannels;
|
||||
use FireflyIII\Notifications\ReturnsSettings;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Notifications\Messages\SlackMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
use NotificationChannels\Pushover\PushoverMessage;
|
||||
use Ntfy\Message;
|
||||
|
||||
class MFABackupFewLeftNotification extends Notification
|
||||
{
|
||||
@ -70,7 +73,27 @@ class MFABackupFewLeftNotification extends Notification
|
||||
{
|
||||
$message = (string) trans('email.mfa_few_backups_left_slack', ['email' => $this->user->email, 'count' => $this->count]);
|
||||
|
||||
return (new SlackMessage())->content($message);
|
||||
return new SlackMessage()->content($message);
|
||||
}
|
||||
|
||||
public function toNtfy(User $notifiable): Message
|
||||
{
|
||||
$settings = ReturnsSettings::getSettings('ntfy', 'user', $notifiable);
|
||||
$message = new Message();
|
||||
$message->topic($settings['ntfy_topic']);
|
||||
$message->title((string) trans('email.mfa_few_backups_left_subject'));
|
||||
$message->body((string) trans('email.mfa_few_backups_left_slack', ['email' => $this->user->email, 'count' => $this->count]));
|
||||
|
||||
return $message;
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function toPushover(User $notifiable): PushoverMessage
|
||||
{
|
||||
return PushoverMessage::create((string) trans('email.mfa_few_backups_left_slack', ['email' => $this->user->email, 'count' => $this->count]))
|
||||
->title((string) trans('email.mfa_few_backups_left_subject'));
|
||||
}
|
||||
|
||||
|
||||
|
@ -25,11 +25,14 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Notifications\Security;
|
||||
|
||||
use FireflyIII\Notifications\ReturnsAvailableChannels;
|
||||
use FireflyIII\Notifications\ReturnsSettings;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Notifications\Messages\SlackMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
use NotificationChannels\Pushover\PushoverMessage;
|
||||
use Ntfy\Message;
|
||||
|
||||
class MFABackupNoLeftNotification extends Notification
|
||||
{
|
||||
@ -69,7 +72,27 @@ class MFABackupNoLeftNotification extends Notification
|
||||
{
|
||||
$message = (string) trans('email.mfa_no_backups_left_slack', ['email' => $this->user->email]);
|
||||
|
||||
return (new SlackMessage())->content($message);
|
||||
return new SlackMessage()->content($message);
|
||||
}
|
||||
|
||||
public function toNtfy(User $notifiable): Message
|
||||
{
|
||||
$settings = ReturnsSettings::getSettings('ntfy', 'user', $notifiable);
|
||||
$message = new Message();
|
||||
$message->topic($settings['ntfy_topic']);
|
||||
$message->title((string) trans('email.mfa_no_backups_left_subject'));
|
||||
$message->body((string) trans('email.mfa_no_backups_left_slack', ['email' => $this->user->email]));
|
||||
|
||||
return $message;
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function toPushover(User $notifiable): PushoverMessage
|
||||
{
|
||||
return PushoverMessage::create((string) trans('email.mfa_few_backups_left_slack', ['email' => $this->user->email]))
|
||||
->title((string) trans('email.mfa_no_backups_left_slack'));
|
||||
}
|
||||
|
||||
|
||||
|
@ -25,11 +25,14 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Notifications\Security;
|
||||
|
||||
use FireflyIII\Notifications\ReturnsAvailableChannels;
|
||||
use FireflyIII\Notifications\ReturnsSettings;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Notifications\Messages\SlackMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
use NotificationChannels\Pushover\PushoverMessage;
|
||||
use Ntfy\Message;
|
||||
|
||||
class MFAManyFailedAttemptsNotification extends Notification
|
||||
{
|
||||
@ -68,7 +71,27 @@ class MFAManyFailedAttemptsNotification extends Notification
|
||||
{
|
||||
$message = (string) trans('email.mfa_many_failed_slack', ['email' => $this->user->email, 'count' => $this->count]);
|
||||
|
||||
return (new SlackMessage())->content($message);
|
||||
return new SlackMessage()->content($message);
|
||||
}
|
||||
|
||||
public function toNtfy(User $notifiable): Message
|
||||
{
|
||||
$settings = ReturnsSettings::getSettings('ntfy', 'user', $notifiable);
|
||||
$message = new Message();
|
||||
$message->topic($settings['ntfy_topic']);
|
||||
$message->title((string) trans('email.mfa_many_failed_subject'));
|
||||
$message->body((string) trans('email.mfa_many_failed_slack', ['email' => $this->user->email, 'count' => $this->count]));
|
||||
|
||||
return $message;
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function toPushover(User $notifiable): PushoverMessage
|
||||
{
|
||||
return PushoverMessage::create((string) trans('email.mfa_many_failed_slack', ['email' => $this->user->email, 'count' => $this->count]))
|
||||
->title((string) trans('email.mfa_many_failed_subject'));
|
||||
}
|
||||
|
||||
|
||||
|
@ -25,11 +25,14 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Notifications\Security;
|
||||
|
||||
use FireflyIII\Notifications\ReturnsAvailableChannels;
|
||||
use FireflyIII\Notifications\ReturnsSettings;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Notifications\Messages\SlackMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
use NotificationChannels\Pushover\PushoverMessage;
|
||||
use Ntfy\Message;
|
||||
|
||||
class MFAUsedBackupCodeNotification extends Notification
|
||||
{
|
||||
@ -69,9 +72,28 @@ class MFAUsedBackupCodeNotification extends Notification
|
||||
{
|
||||
$message = (string) trans('email.used_backup_code_slack', ['email' => $this->user->email]);
|
||||
|
||||
return (new SlackMessage())->content($message);
|
||||
return new SlackMessage()->content($message);
|
||||
}
|
||||
|
||||
public function toNtfy(User $notifiable): Message
|
||||
{
|
||||
$settings = ReturnsSettings::getSettings('ntfy', 'user', $notifiable);
|
||||
$message = new Message();
|
||||
$message->topic($settings['ntfy_topic']);
|
||||
$message->title((string) trans('email.used_backup_code_subject'));
|
||||
$message->body((string) trans('email.used_backup_code_slack', ['email' => $this->user->email]));
|
||||
|
||||
return $message;
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function toPushover(User $notifiable): PushoverMessage
|
||||
{
|
||||
return PushoverMessage::create((string) trans('email.used_backup_code_slack', ['email' => $this->user->email]))
|
||||
->title((string) trans('email.used_backup_code_subject'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
|
@ -25,11 +25,14 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Notifications\Security;
|
||||
|
||||
use FireflyIII\Notifications\ReturnsAvailableChannels;
|
||||
use FireflyIII\Notifications\ReturnsSettings;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Notifications\Messages\SlackMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
use NotificationChannels\Pushover\PushoverMessage;
|
||||
use Ntfy\Message;
|
||||
|
||||
class NewBackupCodesNotification extends Notification
|
||||
{
|
||||
@ -69,7 +72,27 @@ class NewBackupCodesNotification extends Notification
|
||||
{
|
||||
$message = (string) trans('email.new_backup_codes_slack', ['email' => $this->user->email]);
|
||||
|
||||
return (new SlackMessage())->content($message);
|
||||
return new SlackMessage()->content($message);
|
||||
}
|
||||
|
||||
public function toNtfy(User $notifiable): Message
|
||||
{
|
||||
$settings = ReturnsSettings::getSettings('ntfy', 'user', $notifiable);
|
||||
$message = new Message();
|
||||
$message->topic($settings['ntfy_topic']);
|
||||
$message->title((string) trans('email.new_backup_codes_subject'));
|
||||
$message->body((string) trans('email.new_backup_codes_slack', ['email' => $this->user->email]));
|
||||
|
||||
return $message;
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function toPushover(User $notifiable): PushoverMessage
|
||||
{
|
||||
return PushoverMessage::create((string) trans('email.new_backup_codes_slack', ['email' => $this->user->email]))
|
||||
->title((string) trans('email.new_backup_codes_subject'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -24,11 +24,14 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Notifications\Security;
|
||||
|
||||
use FireflyIII\Notifications\ReturnsAvailableChannels;
|
||||
use FireflyIII\Notifications\ReturnsSettings;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Notifications\Messages\SlackMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
use NotificationChannels\Pushover\PushoverMessage;
|
||||
use Ntfy\Message;
|
||||
|
||||
class UserFailedLoginAttempt extends Notification
|
||||
{
|
||||
@ -54,9 +57,9 @@ class UserFailedLoginAttempt extends Notification
|
||||
*/
|
||||
public function toMail(User $notifiable)
|
||||
{
|
||||
$subject = (string) trans('email.new_backup_codes_subject');
|
||||
$subject = (string) trans('email.failed_login_subject');
|
||||
|
||||
return (new MailMessage())->markdown('emails.security.new-backup-codes', ['user' => $this->user])->subject($subject);
|
||||
return (new MailMessage())->markdown('emails.security.failed-login', ['user' => $this->user])->subject($subject);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -64,9 +67,29 @@ class UserFailedLoginAttempt extends Notification
|
||||
*/
|
||||
public function toSlack(User $notifiable)
|
||||
{
|
||||
$message = (string) trans('email.new_backup_codes_slack', ['email' => $this->user->email]);
|
||||
$message = (string) trans('email.failed_login_message', ['email' => $this->user->email]);
|
||||
|
||||
return (new SlackMessage())->content($message);
|
||||
return new SlackMessage()->content($message);
|
||||
}
|
||||
|
||||
public function toNtfy(User $notifiable): Message
|
||||
{
|
||||
$settings = ReturnsSettings::getSettings('ntfy', 'user', $notifiable);
|
||||
$message = new Message();
|
||||
$message->topic($settings['ntfy_topic']);
|
||||
$message->title((string) trans('email.failed_login_subject'));
|
||||
$message->body((string) trans('email.failed_login_message', ['email' => $this->user->email]));
|
||||
|
||||
return $message;
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function toPushover(User $notifiable): PushoverMessage
|
||||
{
|
||||
return PushoverMessage::create((string) trans('email.failed_login_message', ['email' => $this->user->email]))
|
||||
->title((string) trans('email.failed_login_subject'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -88,7 +88,7 @@ class BillReminder extends Notification
|
||||
$bill = $this->bill;
|
||||
$url = route('bills.show', [$bill->id]);
|
||||
|
||||
return (new SlackMessage())
|
||||
return new SlackMessage()
|
||||
->warning()
|
||||
->attachment(static function ($attachment) use ($bill, $url): void {
|
||||
$attachment->title((string) trans('firefly.visit_bill', ['name' => $bill->name]), $url);
|
||||
|
@ -63,7 +63,7 @@ class NewAccessToken extends Notification
|
||||
*/
|
||||
public function toSlack(User $notifiable)
|
||||
{
|
||||
return (new SlackMessage())->content((string) trans('email.access_token_created_body'));
|
||||
return new SlackMessage()->content((string) trans('email.access_token_created_body'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -73,7 +73,7 @@ class RuleActionFailed extends Notification
|
||||
$ruleTitle = $this->ruleTitle;
|
||||
$ruleLink = $this->ruleLink;
|
||||
|
||||
return (new SlackMessage())->content($this->message)->attachment(static function ($attachment) use ($groupTitle, $groupLink): void {
|
||||
return new SlackMessage()->content($this->message)->attachment(static function ($attachment) use ($groupTitle, $groupLink): void {
|
||||
$attachment->title((string) trans('rules.inspect_transaction', ['title' => $groupTitle]), $groupLink);
|
||||
})->attachment(static function ($attachment) use ($ruleTitle, $ruleLink): void {
|
||||
$attachment->title((string) trans('rules.inspect_rule', ['title' => $ruleTitle]), $ruleLink);
|
||||
|
@ -94,7 +94,7 @@ class UserLogin extends Notification
|
||||
$host = $hostName;
|
||||
}
|
||||
|
||||
return (new SlackMessage())->content((string) trans('email.slack_login_from_new_ip', ['host' => $host, 'ip' => $this->ip]));
|
||||
return new SlackMessage()->content((string) trans('email.slack_login_from_new_ip', ['host' => $host, 'ip' => $this->ip]));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -66,6 +66,12 @@ return [
|
||||
'unknown_user_body' => 'An unknown user tried to log in to Firefly III. The email address they used was ":address".',
|
||||
'unknown_user_message' => 'The email address they used was ":address".',
|
||||
|
||||
// known user login attempt
|
||||
'failed_login_subject' => 'Firefly III detected a failed login attempt',
|
||||
'failed_login_body' => 'Firefly III detected that somebody (you?) failed to login with your account ":email". Please verify that this was you.',
|
||||
'failed_login_message' => 'A failed login attempt on your Firefly III account ":email" was detected.',
|
||||
'failed_login_warning' => 'If you recognize this IP address or the login attempt, you can ignore this message. If you didn\'t try to login, of if you have no idea what this is about, verify your password security, change it, and log out all other sessions. To do this, go to your profile page. Of course you have 2FA enabled already, right? Stay safe!',
|
||||
|
||||
// registered
|
||||
'registered_subject' => 'Welcome to Firefly III!',
|
||||
'registered_subject_admin' => 'A new user has registered',
|
||||
|
6
resources/views/emails/security/failed-login.blade.php
Normal file
6
resources/views/emails/security/failed-login.blade.php
Normal file
@ -0,0 +1,6 @@
|
||||
@component('mail::message')
|
||||
{{ trans('email.failed_login_body', ['email' => $user->email]) }}
|
||||
|
||||
{{ trans('email.failed_login_warning') }}
|
||||
|
||||
@endcomponent
|
Loading…
Reference in New Issue
Block a user