diff --git a/app/Notifications/Admin/TestNotification.php b/app/Notifications/Admin/TestNotification.php index f0e1948a70..9392460e83 100644 --- a/app/Notifications/Admin/TestNotification.php +++ b/app/Notifications/Admin/TestNotification.php @@ -22,7 +22,6 @@ declare(strict_types=1); namespace FireflyIII\Notifications\Admin; -use FireflyIII\Mail\AdminTestMail; use Illuminate\Bus\Queueable; use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Notifications\Messages\SlackMessage; @@ -50,7 +49,7 @@ class TestNotification extends Notification /** * Get the notification's delivery channels. * - * @param mixed $notifiable + * @param mixed $notifiable * @return array */ public function via($notifiable) @@ -61,7 +60,7 @@ class TestNotification extends Notification /** * Get the mail representation of the notification. * - * @param mixed $notifiable + * @param mixed $notifiable * @return \Illuminate\Notifications\Messages\MailMessage */ public function toMail($notifiable) @@ -70,6 +69,7 @@ class TestNotification extends Notification ->markdown('emails.admin-test', ['email' => $this->address]) ->subject((string) trans('email.admin_test_subject')); } + /** * Get the Slack representation of the notification. * @@ -78,13 +78,13 @@ class TestNotification extends Notification */ public function toSlack($notifiable) { - return (new SlackMessage)->content((string)trans('email.admin_test_subject')); + return (new SlackMessage)->content((string) trans('email.admin_test_subject')); } /** * Get the array representation of the notification. * - * @param mixed $notifiable + * @param mixed $notifiable * @return array */ public function toArray($notifiable) diff --git a/app/Notifications/User/NewAccessToken.php b/app/Notifications/User/NewAccessToken.php index 30ead2627f..a8e65e3a3c 100644 --- a/app/Notifications/User/NewAccessToken.php +++ b/app/Notifications/User/NewAccessToken.php @@ -24,6 +24,7 @@ namespace FireflyIII\Notifications\User; use Illuminate\Bus\Queueable; use Illuminate\Notifications\Messages\MailMessage; +use Illuminate\Notifications\Messages\SlackMessage; use Illuminate\Notifications\Notification; class NewAccessToken extends Notification @@ -47,7 +48,7 @@ class NewAccessToken extends Notification */ public function via($notifiable) { - return ['mail']; + return ['mail', 'slack']; } /** @@ -62,6 +63,16 @@ class NewAccessToken extends Notification ->markdown('emails.token-created') ->subject((string) trans('email.access_token_created_subject')); } + /** + * Get the Slack representation of the notification. + * + * @param mixed $notifiable + * @return SlackMessage + */ + public function toSlack($notifiable) + { + return (new SlackMessage)->content((string) trans('email.access_token_created_body')); + } /** * Get the array representation of the notification. diff --git a/app/Notifications/User/UserLogin.php b/app/Notifications/User/UserLogin.php index 382c02cff5..ff39185563 100644 --- a/app/Notifications/User/UserLogin.php +++ b/app/Notifications/User/UserLogin.php @@ -25,6 +25,7 @@ namespace FireflyIII\Notifications\User; use Exception; use Illuminate\Bus\Queueable; use Illuminate\Notifications\Messages\MailMessage; +use Illuminate\Notifications\Messages\SlackMessage; use Illuminate\Notifications\Notification; class UserLogin extends Notification @@ -51,7 +52,7 @@ class UserLogin extends Notification */ public function via($notifiable) { - return ['mail']; + return ['mail', 'slack']; } /** @@ -78,6 +79,27 @@ class UserLogin extends Notification ->subject((string) trans('email.login_from_new_ip')); } + /** + * Get the Slack representation of the notification. + * + * @param mixed $notifiable + * @return SlackMessage + */ + public function toSlack($notifiable) + { + $host = ''; + try { + $hostName = gethostbyaddr($this->ip); + } catch (Exception $e) { + $hostName = $this->ip; + } + if ($hostName !== $this->ip) { + $host = $hostName; + } + + return (new SlackMessage)->content((string) trans('email.slack_login_from_new_ip', ['host' => $host, 'ip' => $this->ip])); + } + /** * Get the array representation of the notification. * diff --git a/resources/lang/en_US/email.php b/resources/lang/en_US/email.php index cadb14c1a5..f796c7b82d 100644 --- a/resources/lang/en_US/email.php +++ b/resources/lang/en_US/email.php @@ -35,6 +35,7 @@ return [ // new IP 'login_from_new_ip' => 'New login on Firefly III', + 'slack_login_from_new_ip' => 'New Firefly III login from IP :ip (:host)', 'new_ip_body' => 'Firefly III detected a new login on your account from an unknown IP address. If you never logged in from the IP address below, or it has been more than six months ago, Firefly III will warn you.', 'new_ip_warning' => 'If you recognize this IP address or the login, you can ignore this message. If you didn\'t 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!', 'ip_address' => 'IP address',