Files
coolify/app/Notifications/Channels/TransactionalEmailChannel.php
Andras Bacsai ee502b9f76 feat(email): implement email change request and verification process
- Added functionality for users to request an email change, including generating a verification code and setting an expiration time.
- Implemented methods in the User model to handle email change requests, code validation, and confirmation.
- Created a new job to update the user's email in Stripe after confirmation.
- Introduced rate limiting for email change requests and verification attempts to prevent abuse.
- Added a new notification for email change verification.
- Updated the profile component to manage email change requests and verification UI.
2025-08-18 14:54:08 +02:00

48 lines
1.3 KiB
PHP

<?php
namespace App\Notifications\Channels;
use App\Models\User;
use Exception;
use Illuminate\Mail\Message;
use Illuminate\Notifications\Notification;
use Illuminate\Support\Facades\Mail;
class TransactionalEmailChannel
{
public function send(User $notifiable, Notification $notification): void
{
$settings = instanceSettings();
if (! data_get($settings, 'smtp_enabled') && ! data_get($settings, 'resend_enabled')) {
return;
}
// Check if notification has a custom recipient (for email changes)
$email = property_exists($notification, 'newEmail') && $notification->newEmail
? $notification->newEmail
: $notifiable->email;
if (! $email) {
return;
}
$this->bootConfigs();
$mailMessage = $notification->toMail($notifiable);
Mail::send(
[],
[],
fn (Message $message) => $message
->to($email)
->subject($mailMessage->subject)
->html((string) $mailMessage->render())
);
}
private function bootConfigs(): void
{
$type = set_transanctional_email_settings();
if (blank($type)) {
throw new Exception('No email settings found.');
}
}
}