Skip to content

Commit 67f05d5

Browse files
committed
Tweak email rendering & verbiage
1 parent 96b3c98 commit 67f05d5

File tree

7 files changed

+67
-25
lines changed

7 files changed

+67
-25
lines changed

resources/lang/en/mail.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
'greeting' => 'Hello,',
99
'line1' => 'A request has been made on your account to change your email address to :email. Please click the button below to verify your new email address.',
1010
'button' => 'Verify new email address',
11-
'line2' => 'Note: This link will expire in :minutes minutes.',
11+
'line2' => "Heads up — this link only works for :expire. After that, you'll need to request a new one to verify your email address.",
1212
'line3' => 'If you did not update your email address, no further action is required.',
1313
'salutation' => 'Thanks,<br>:app_name',
1414
],
@@ -19,7 +19,7 @@
1919
'line1' => 'You are receiving this email because your :app_name account email address was recently updated.',
2020
'line2' => 'From now on, you will need to use ":email" to sign into your account.',
2121
'line3' => 'If this was you, no further action is required.',
22-
'line4' => 'If you did not initiate this change, [click this link](:url) to revert the change. This link will expire in :days days.',
22+
'line4' => 'If you did not initiate this change, [click this link](:url) to revert the change. This link will expire in :expire.',
2323
'salutation' => 'Thanks,<br>:app_name',
2424
],
2525

resources/lang/pl/mail.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
'greeting' => 'Witaj,',
99
'line1' => 'Złożono prośbę o zmianę adresu e-mail na Twoim koncie na :email. Kliknij poniższy przycisk, aby zweryfikować swój nowy adres e-mail.',
1010
'button' => 'Zweryfikuj nowy adres e-mail',
11-
'line2' => 'Uwaga: Ten link wygaśnie za :minutes minut.',
11+
'line2' => 'Uwaga — ten link działa tylko przez :expire. Po tym czasie musisz poprosić o nowy, aby zweryfikować swój adres e-mail.',
1212
'line3' => 'Jeśli nie aktualizowałeś swojego adresu e-mail, nie musisz podejmować żadnych działań.',
1313
'salutation' => 'Dziękujemy,<br>:app_name',
1414
],
@@ -19,7 +19,7 @@
1919
'line1' => 'Otrzymujesz tę wiadomość, ponieważ adres e-mail Twojego konta :app_name został niedawno zaktualizowany.',
2020
'line2' => 'Od teraz będziesz musiał używać adresu ":email" do logowania się na swoje konto.',
2121
'line3' => 'Jeśli to Ty dokonałeś tej zmiany, nie musisz podejmować żadnych dalszych działań.',
22-
'line4' => 'Jeśli nie zainicjowałeś tej zmiany, [kliknij ten link](:url), aby cofnąć zmianę. Ten link wygaśnie za :days dni.',
22+
'line4' => 'Jeśli nie zainicjowałeś tej zmiany, [kliknij ten link](:url), aby cofnąć zmianę. Ten link wygaśnie za :expire.',
2323
'salutation' => 'Dziękujemy,<br>:app_name',
2424
],
2525

resources/lang/pt_BR/mail.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
'greeting' => 'Olá,',
99
'line1' => 'Foi feita uma solicitação na sua conta para alterar seu endereço de e-mail para :email. Por favor, clique no botão abaixo para verificar seu novo endereço de e-mail.',
1010
'button' => 'Verificar novo endereço de e-mail',
11-
'line2' => 'Nota: Este link expirará em :minutes minutos.',
11+
'line2' => 'Atenção — este link só funciona por :expire. Depois disso, será necessário solicitar um novo para verificar seu endereço de e-mail.',
1212
'line3' => 'Se você não atualizou seu endereço de e-mail, nenhuma ação adicional é necessária.',
1313
'salutation' => 'Obrigado,<br>:app_name',
1414
],
@@ -19,7 +19,7 @@
1919
'line1' => 'Você está recebendo este e-mail porque o endereço de e-mail da sua conta :app_name foi atualizado recentemente.',
2020
'line2' => 'A partir de agora, você precisará usar ":email" para entrar na sua conta.',
2121
'line3' => 'Se foi você que fez esta alteração, nenhuma ação adicional é necessária.',
22-
'line4' => 'Se você não iniciou esta alteração, [clique neste link](:url) para reverter a alteração. Este link expirará em :days dias.',
22+
'line4' => 'Se você não iniciou esta alteração, [clique neste link](:url) para reverter a alteração. Este link expirará em :expire.',
2323
'salutation' => 'Obrigado,<br>:app_name',
2424
],
2525

resources/views/mail/email-updated.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
{{ __('profile-filament::mail.email_updated.line3') }}
99

10-
{{ __('profile-filament::mail.email_updated.line4', ['url' => $url, 'days' => $linkExpirationDays]) }}
10+
{{ __('profile-filament::mail.email_updated.line4', ['url' => $url, 'expire' => $linkExpires]) }}
1111

1212
{{ str($requestDetails)->inlineMarkdown()->toHtmlString() }}
1313

resources/views/mail/pending-email-verification.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
{{ __('profile-filament::mail.pending_email_verification.button') }}
88
</x-mail::button>
99

10-
{{ __('profile-filament::mail.pending_email_verification.line2', ['minutes' => config('auth.verification.expire', 60)]) }}
10+
{{ __('profile-filament::mail.pending_email_verification.line2', ['expire' => $linkExpires]) }}
1111

1212
{{ __('profile-filament::mail.pending_email_verification.line3') }}
1313

src/Mail/PendingEmailVerificationMail.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,17 @@ public function content(): Content
4141
with: [
4242
'url' => $this->pendingUserEmail->verification_url,
4343
'email' => $this->pendingUserEmail->email,
44+
'linkExpires' => $this->getLinkExpiration(),
4445
],
4546
);
4647
}
48+
49+
protected function getLinkExpiration(): string
50+
{
51+
return now()->diffForHumans(
52+
other: now()->addMinutes(config('auth.verification.expire', 60)),
53+
syntax: true,
54+
parts: 2,
55+
);
56+
}
4757
}

src/Mail/PendingEmailVerifiedMail.php

Lines changed: 49 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77
use DateTimeInterface;
88
use Illuminate\Bus\Queueable;
99
use Illuminate\Contracts\Queue\ShouldQueue;
10+
use Illuminate\Contracts\Support\Htmlable;
1011
use Illuminate\Mail\Mailable;
1112
use Illuminate\Mail\Mailables\Content;
1213
use Illuminate\Mail\Mailables\Envelope;
1314
use Illuminate\Queue\SerializesModels;
1415
use Illuminate\Support\Str;
16+
use Illuminate\Support\Stringable;
1517
use Rawilk\ProfileFilament\Models\OldUserEmail;
1618

1719
class PendingEmailVerifiedMail extends Mailable implements ShouldQueue
@@ -46,36 +48,66 @@ public function content(): Content
4648
with: [
4749
'maskedEmail' => $this->anonymizeEmail($this->newEmail),
4850
'url' => $this->oldUserEmail->revert_url,
49-
'linkExpirationDays' => now()->diffInDays(now()->add(config('profile-filament.pending_email_changes.revert_expiration'))),
51+
'linkExpires' => $this->getLinkExpiration(),
5052
'requestDetails' => $this->requestDetailsMarkup(),
5153
],
5254
);
5355
}
5456

55-
protected function requestDetailsMarkup(): ?string
57+
protected function getLinkExpiration(): string
58+
{
59+
return now()->diffForHumans(
60+
other: now()->add(config('profile-filament.pending_email_changes.revert_expiration')),
61+
syntax: true,
62+
parts: 2,
63+
);
64+
}
65+
66+
protected function requestDetailsMarkup(): ?Htmlable
5667
{
5768
if (! $this->ip && ! $this->date) {
5869
return null;
5970
}
6071

61-
$markup = __('profile-filament::mail.request_details.heading');
62-
63-
if ($this->ip) {
64-
$markup .= '<br>' . __('profile-filament::mail.request_details.ip', ['ip' => $this->ip]);
65-
}
66-
67-
if ($this->date) {
68-
$markup .= '<br>' . __('profile-filament::mail.request_details.date', ['date' => $this->date->format('D, j M Y g:i A (T O)')]);
69-
}
70-
71-
return $markup;
72+
return str(__('profile-filament::mail.request_details.heading'))
73+
->when(
74+
filled($this->ip),
75+
fn (Stringable $str) => $str->append('<br>', __('profile-filament::mail.request_details.ip', ['ip' => $this->ip])),
76+
)
77+
->when(
78+
$this->date !== null,
79+
fn (Stringable $str) => $str->append('<br>', __('profile-filament::mail.request_details.date', ['date' => $this->date->format('D, j M Y g:i A (T O)')])),
80+
)
81+
->inlineMarkdown()
82+
->toHtmlString();
7283
}
7384

7485
protected function anonymizeEmail(string $email): string
7586
{
76-
[$handle, $host] = explode('@', $email);
77-
[$hostName, $tld] = explode('.', $host, 2);
78-
79-
return Str::mask($handle, '*', 2) . '@' . Str::mask($hostName, '*', 2) . '.' . $tld;
87+
return Str::of($email)
88+
->before('@')
89+
// Mask the handle:
90+
// - >= 5 chars: reveal first & last 2, mask the middle
91+
// - 2-4 chars: reveal first character, mask the rest
92+
// - 1 char: mask the entire string
93+
->when(
94+
fn (Stringable $str): bool => $str->length() >= 5,
95+
fn (Stringable $str): Stringable => $str->mask('*', 2, -2),
96+
fn (Stringable $str): Stringable => $str->when(
97+
fn (Stringable $str): bool => $str->length() >= 2,
98+
fn (Stringable $str): Stringable => $str->mask('*', 1),
99+
fn (Stringable $str): Stringable => $str->mask('*', 0),
100+
),
101+
)
102+
->append('@')
103+
// Mask the host name
104+
->append(
105+
Str::of(Str::after($email, '@'))
106+
->beforeLast('.')
107+
->mask('*', 2)
108+
)
109+
->append('.')
110+
->append(Str::afterLast('.', $email))
111+
->value();
80112
}
81113
}

0 commit comments

Comments
 (0)