Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/Http/Middleware/RateLimitOutboundMail.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use App\Jobs\SendDisableUserMail;
use App\Jobs\SendMassEmail;
use Closure;
use Illuminate\Notifications\SendQueuedNotifications;
use Illuminate\Support\Facades\Redis;

class RateLimitOutboundMail
Expand All @@ -29,7 +30,7 @@ class RateLimitOutboundMail
*
* @param Closure(object): void $next
*/
public function handle(SendDeleteUserMail|SendDisableUserMail|SendMassEmail $job, Closure $next): void
public function handle(SendQueuedNotifications|SendDeleteUserMail|SendDisableUserMail|SendMassEmail $job, Closure $next): void
{
Redis::throttle(config('cache.prefix').':outbound-email-limiter')
->allow(config('other.mail.allow'))
Expand Down
4 changes: 2 additions & 2 deletions app/Jobs/SendDeleteUserMail.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ class SendDeleteUserMail implements ShouldQueue
use SerializesModels;

/**
* The number of times the job may be attempted.
* The maximum number of unhandled exceptions to allow before failing.
*/
public int $tries = 3;
public int $maxExceptions = 1;

/**
* SendDeleteUserMail Constructor.
Expand Down
4 changes: 2 additions & 2 deletions app/Jobs/SendDisableUserMail.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ class SendDisableUserMail implements ShouldQueue
use SerializesModels;

/**
* The number of times the job may be attempted.
* The maximum number of unhandled exceptions to allow before failing.
*/
public int $tries = 3;
public int $maxExceptions = 1;

/**
* SendDisableUserMail Constructor.
Expand Down
4 changes: 2 additions & 2 deletions app/Jobs/SendMassEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ class SendMassEmail implements ShouldQueue
use SerializesModels;

/**
* The number of times the job may be attempted.
* The maximum number of unhandled exceptions to allow before failing.
*/
public int $tries = 3;
public int $maxExceptions = 1;

/**
* Create a new job instance.
Expand Down
28 changes: 28 additions & 0 deletions app/Notifications/FailedLogin.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

namespace App\Notifications;

use App\Http\Middleware\RateLimitOutboundMail;
use App\Models\User;
use DateTime;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
Expand All @@ -27,6 +29,11 @@ class FailedLogin extends Notification implements ShouldQueue
{
use Queueable;

/**
* The maximum number of unhandled exceptions to allow before failing.
*/
public int $maxExceptions = 1;

/**
* FailedLogin Constructor.
*/
Expand All @@ -44,6 +51,19 @@ public function via(object $notifiable): array
return ['mail'];
}

/**
* Get the middleware the job should pass through.
*
* @return array<int, object>
*/
public function middleware(object $notifiable, string $channel): array
{
return match ($channel) {
'mail' => [new RateLimitOutboundMail()],
default => [],
};
}

/**
* Determine if the notification should be sent.
*/
Expand All @@ -69,4 +89,12 @@ public function toMail(object $notifiable): MailMessage
{
return (new MailMessage())->error()->subject(trans('email.fail-login-subject'))->greeting(trans('email.fail-login-greeting'))->line(trans('email.fail-login-line1'))->line(trans('email.fail-login-line2', ['ip' => $this->ip, 'host' => gethostbyaddr($this->ip), 'time' => Carbon::now()->__toString()]));
}

/**
* Determine the time at which the job should timeout.
*/
public function retryUntil(): DateTime
{
return now()->addHours(2);
}
}
31 changes: 30 additions & 1 deletion app/Notifications/MassEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,22 @@

namespace App\Notifications;

use App\Http\Middleware\RateLimitOutboundMail;
use DateTime;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;

class MassEmail extends Notification
class MassEmail extends Notification implements ShouldQueue
{
use Queueable;

/**
* The maximum number of unhandled exceptions to allow before failing.
*/
public int $maxExceptions = 1;

/**
* Create a new notification instance.
*/
Expand All @@ -41,6 +49,19 @@ public function via(object $notifiable): array
return ['mail'];
}

/**
* Get the middleware the job should pass through.
*
* @return array<int, object>
*/
public function middleware(object $notifiable, string $channel): array
{
return match ($channel) {
'mail' => [new RateLimitOutboundMail()],
default => [],
};
}

/**
* Get the mail representation of the notification.
*/
Expand All @@ -52,4 +73,12 @@ public function toMail(object $notifiable): MailMessage
->action('Login Now', route('login'))
->line('Thank you for using 🚀'.config('other.title'));
}

/**
* Determine the time at which the job should timeout.
*/
public function retryUntil(): DateTime
{
return now()->addHours(2);
}
}
31 changes: 30 additions & 1 deletion app/Notifications/UserBan.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,23 @@

namespace App\Notifications;

use App\Http\Middleware\RateLimitOutboundMail;
use App\Models\Ban;
use DateTime;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;

class UserBan extends Notification
class UserBan extends Notification implements ShouldQueue
{
use Queueable;

/**
* The maximum number of unhandled exceptions to allow before failing.
*/
public int $maxExceptions = 1;

/**
* Create a new notification instance.
*/
Expand All @@ -42,6 +50,19 @@ public function via(object $notifiable): array
return ['mail'];
}

/**
* Get the middleware the job should pass through.
*
* @return array<int, object>
*/
public function middleware(object $notifiable, string $channel): array
{
return match ($channel) {
'mail' => [new RateLimitOutboundMail()],
default => [],
};
}

/**
* Get the mail representation of the notification.
*/
Expand All @@ -55,4 +76,12 @@ public function toMail(object $notifiable): MailMessage
->action('Need Support?', $chatUrl)
->line('Thank you for using 🚀'.config('other.title'));
}

/**
* Determine the time at which the job should timeout.
*/
public function retryUntil(): DateTime
{
return now()->addHours(2);
}
}
31 changes: 30 additions & 1 deletion app/Notifications/UserBanExpire.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,22 @@

namespace App\Notifications;

use App\Http\Middleware\RateLimitOutboundMail;
use DateTime;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;

class UserBanExpire extends Notification
class UserBanExpire extends Notification implements ShouldQueue
{
use Queueable;

/**
* The maximum number of unhandled exceptions to allow before failing.
*/
public int $maxExceptions = 1;

/**
* Create a new notification instance.
*/
Expand All @@ -41,6 +49,19 @@ public function via(object $notifiable): array
return ['mail'];
}

/**
* Get the middleware the job should pass through.
*
* @return array<int, object>
*/
public function middleware(object $notifiable, string $channel): array
{
return match ($channel) {
'mail' => [new RateLimitOutboundMail()],
default => [],
};
}

/**
* Get the mail representation of the notification.
*/
Expand All @@ -51,4 +72,12 @@ public function toMail(object $notifiable): MailMessage
->line('You have been unbanned from '.config('other.title'))
->line('Thank you for using 🚀'.config('other.title'));
}

/**
* Determine the time at which the job should timeout.
*/
public function retryUntil(): DateTime
{
return now()->addHours(2);
}
}
31 changes: 30 additions & 1 deletion app/Notifications/UserEmailChange.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,23 @@

namespace App\Notifications;

use App\Http\Middleware\RateLimitOutboundMail;
use App\Models\User;
use DateTime;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;

class UserEmailChange extends Notification
class UserEmailChange extends Notification implements ShouldQueue
{
use Queueable;

/**
* The maximum number of unhandled exceptions to allow before failing.
*/
public int $maxExceptions = 1;

/**
* Create a new notification instance.
*/
Expand All @@ -42,6 +50,19 @@ public function via(object $notifiable): array
return ['mail'];
}

/**
* Get the middleware the job should pass through.
*
* @return array<int, object>
*/
public function middleware(object $notifiable, string $channel): array
{
return match ($channel) {
'mail' => [new RateLimitOutboundMail()],
default => [],
};
}

/**
* Get the mail representation of the notification.
*/
Expand All @@ -53,4 +74,12 @@ public function toMail(object $notifiable): MailMessage
->action('Helpdesk', route('tickets.index'))
->line('Thank you for using 🚀'.config('other.title'));
}

/**
* Determine the time at which the job should timeout.
*/
public function retryUntil(): DateTime
{
return now()->addHours(2);
}
}
31 changes: 30 additions & 1 deletion app/Notifications/UserManualWarningExpire.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,24 @@

namespace App\Notifications;

use App\Http\Middleware\RateLimitOutboundMail;
use App\Models\User;
use App\Models\Warning;
use DateTime;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;

class UserManualWarningExpire extends Notification
class UserManualWarningExpire extends Notification implements ShouldQueue
{
use Queueable;

/**
* The maximum number of unhandled exceptions to allow before failing.
*/
public int $maxExceptions = 1;

/**
* Create a new notification instance.
*/
Expand All @@ -43,6 +51,19 @@ public function via(object $notifiable): array
return ['database', 'mail'];
}

/**
* Get the middleware the job should pass through.
*
* @return array<int, object>
*/
public function middleware(object $notifiable, string $channel): array
{
return match ($channel) {
'mail' => [new RateLimitOutboundMail()],
default => [],
};
}

/**
* Get the mail representation of the notification.
*/
Expand Down Expand Up @@ -70,4 +91,12 @@ public function toArray(object $notifiable): array
'url' => \sprintf('/users/%s', $this->user->username),
];
}

/**
* Determine the time at which the job should timeout.
*/
public function retryUntil(): DateTime
{
return now()->addHours(2);
}
}
Loading