mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-04-15 09:14:08 +00:00
When inviting an email without an InvoiceShelf account, the email now
links to a registration page (/register?invitation={token}) instead of
login. After registering, the invitation is auto-accepted.
Backend:
- InvitationRegistrationController: public details() and register()
endpoints. Registration validates token + email match, creates account,
auto-accepts invitation, returns Sanctum token.
- AuthController: login now accepts optional invitation_token param to
auto-accept invitation for existing users clicking the email link.
- CompanyInvitationMail: conditional URL based on user existence.
- Web route for /invitations/{token}/decline (email decline link).
Frontend:
- RegisterWithInvitation.vue: fetches invitation details, shows company
name + role, registration form with pre-filled email.
- Router: /register route added.
Tests: 3 new tests (invitation details, register + accept, email mismatch).
52 lines
1.5 KiB
PHP
52 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Mail;
|
|
|
|
use App\Models\CompanyInvitation;
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Mail\Mailable;
|
|
use Illuminate\Mail\Mailables\Content;
|
|
use Illuminate\Mail\Mailables\Envelope;
|
|
use Illuminate\Queue\SerializesModels;
|
|
|
|
class CompanyInvitationMail extends Mailable
|
|
{
|
|
use Queueable, SerializesModels;
|
|
|
|
public function __construct(
|
|
public readonly CompanyInvitation $invitation,
|
|
) {}
|
|
|
|
public function envelope(): Envelope
|
|
{
|
|
return new Envelope(
|
|
subject: __('You\'ve been invited to join :company', [
|
|
'company' => $this->invitation->company->name,
|
|
]),
|
|
);
|
|
}
|
|
|
|
public function content(): Content
|
|
{
|
|
$token = $this->invitation->token;
|
|
$hasAccount = $this->invitation->user_id !== null;
|
|
|
|
$acceptUrl = $hasAccount
|
|
? url("/login?invitation={$token}")
|
|
: url("/register?invitation={$token}");
|
|
|
|
return new Content(
|
|
markdown: 'emails.company-invitation',
|
|
with: [
|
|
'invitation' => $this->invitation,
|
|
'companyName' => $this->invitation->company->name,
|
|
'roleName' => $this->invitation->role->title,
|
|
'inviterName' => $this->invitation->invitedBy->name,
|
|
'acceptUrl' => $acceptUrl,
|
|
'declineUrl' => url("/invitations/{$token}/decline"),
|
|
'hasAccount' => $hasAccount,
|
|
],
|
|
);
|
|
}
|
|
}
|