Implement end-to-end invitation acceptance: neutral entry route validates token and routes to register (new users), login (existing users), or auto-accepts (authenticated users). Handles 2FA token survival via session, email case-insensitive matching, and dedicated error pages. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
57 lines
1.5 KiB
PHP
57 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Mail;
|
|
|
|
use App\Models\TeamInvitation;
|
|
use App\Models\Workspace;
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Mail\Mailable;
|
|
use Illuminate\Mail\Mailables\Content;
|
|
use Illuminate\Mail\Mailables\Envelope;
|
|
use Illuminate\Queue\SerializesModels;
|
|
|
|
class TeamInvitationMail extends Mailable implements ShouldQueue
|
|
{
|
|
use Queueable, SerializesModels;
|
|
|
|
/**
|
|
* Create a new message instance.
|
|
*/
|
|
public function __construct(
|
|
public Workspace $workspace,
|
|
public TeamInvitation $invitation
|
|
) {}
|
|
|
|
/**
|
|
* Get the message envelope.
|
|
*/
|
|
public function envelope(): Envelope
|
|
{
|
|
return new Envelope(
|
|
subject: 'Invitation à rejoindre '.$this->workspace->name,
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Get the message content definition.
|
|
*/
|
|
public function content(): Content
|
|
{
|
|
$roleLabels = [
|
|
'manager' => 'Gestionnaire',
|
|
'worker' => 'Collaborateur',
|
|
];
|
|
|
|
return new Content(
|
|
markdown: 'emails.team-invitation',
|
|
with: [
|
|
'workspaceName' => $this->workspace->name,
|
|
'roleLabel' => $roleLabels[$this->invitation->role] ?? $this->invitation->role,
|
|
'acceptUrl' => route('team.invitation.accept', $this->invitation->token),
|
|
'expiresAt' => $this->invitation->expires_at->format('d/m/Y à H:i'),
|
|
]
|
|
);
|
|
}
|
|
}
|