2024-10-08 14:45:37 +02:00
|
|
|
<?php
|
2024-11-25 04:18:55 +01:00
|
|
|
|
2024-10-08 14:45:37 +02:00
|
|
|
/*
|
|
|
|
* EnabledMFANotification.php
|
|
|
|
* Copyright (c) 2024 james@firefly-iii.org.
|
|
|
|
*
|
|
|
|
* 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;
|
|
|
|
|
2024-12-14 07:22:46 +01:00
|
|
|
use FireflyIII\Notifications\ReturnsAvailableChannels;
|
2024-12-14 07:52:02 +01:00
|
|
|
use FireflyIII\Notifications\ReturnsSettings;
|
2024-10-08 14:45:37 +02:00
|
|
|
use FireflyIII\User;
|
|
|
|
use Illuminate\Bus\Queueable;
|
|
|
|
use Illuminate\Notifications\Messages\MailMessage;
|
|
|
|
use Illuminate\Notifications\Messages\SlackMessage;
|
|
|
|
use Illuminate\Notifications\Notification;
|
2024-12-14 07:52:02 +01:00
|
|
|
use NotificationChannels\Pushover\PushoverMessage;
|
|
|
|
use Ntfy\Message;
|
2024-10-08 14:45:37 +02:00
|
|
|
|
|
|
|
class MFAManyFailedAttemptsNotification extends Notification
|
|
|
|
{
|
|
|
|
use Queueable;
|
|
|
|
|
2024-12-14 07:22:46 +01:00
|
|
|
private int $count;
|
|
|
|
private User $user;
|
2024-12-14 07:13:01 +01:00
|
|
|
|
2024-10-08 14:45:37 +02:00
|
|
|
public function __construct(User $user, int $count)
|
|
|
|
{
|
2024-10-14 05:14:52 +02:00
|
|
|
$this->user = $user;
|
2024-10-08 14:45:37 +02:00
|
|
|
$this->count = $count;
|
|
|
|
}
|
|
|
|
|
2024-12-14 07:13:01 +01:00
|
|
|
|
2024-12-14 07:22:46 +01:00
|
|
|
public function toArray(User $notifiable)
|
2024-10-08 14:45:37 +02:00
|
|
|
{
|
|
|
|
return [
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2024-12-14 07:22:46 +01:00
|
|
|
/**
|
|
|
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
|
|
|
*/
|
|
|
|
public function toMail(User $notifiable)
|
2024-10-08 14:45:37 +02:00
|
|
|
{
|
2024-12-14 07:22:46 +01:00
|
|
|
$subject = (string) trans('email.mfa_many_failed_subject', ['count' => $this->count]);
|
2024-10-08 14:45:37 +02:00
|
|
|
|
|
|
|
return (new MailMessage())->markdown('emails.security.many-failed-attempts', ['user' => $this->user, 'count' => $this->count])->subject($subject);
|
|
|
|
}
|
|
|
|
|
2024-12-14 07:22:46 +01:00
|
|
|
/**
|
|
|
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
|
|
|
*/
|
|
|
|
public function toSlack(User $notifiable)
|
2024-10-08 14:45:37 +02:00
|
|
|
{
|
2024-12-14 07:22:46 +01:00
|
|
|
$message = (string) trans('email.mfa_many_failed_slack', ['email' => $this->user->email, 'count' => $this->count]);
|
2024-10-08 14:45:37 +02:00
|
|
|
|
2024-12-14 07:52:02 +01:00
|
|
|
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'));
|
2024-10-08 14:45:37 +02:00
|
|
|
}
|
|
|
|
|
2024-12-14 07:13:01 +01:00
|
|
|
|
2024-12-14 07:22:46 +01:00
|
|
|
/**
|
|
|
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
|
|
|
*/
|
|
|
|
public function via(User $notifiable)
|
2024-10-08 14:45:37 +02:00
|
|
|
{
|
2024-12-14 07:22:46 +01:00
|
|
|
return ReturnsAvailableChannels::returnChannels('user', $notifiable);
|
2024-10-08 14:45:37 +02:00
|
|
|
}
|
|
|
|
}
|