diff --git a/docs/customization/views.md b/docs/customization/views.md index e38961da6..624201a2c 100644 --- a/docs/customization/views.md +++ b/docs/customization/views.md @@ -37,3 +37,5 @@ to the **app/Views/Shield/** folder. ## Customize Content Customize the content of the view file in **app/Views/Shield/** as you like. + +When customizing email templates in **app/Views/Shield/Email**, you have access to the User Entity object through the `$user` variable. Utilize `$user` to personalize the email messages according to individual user details. diff --git a/src/Authentication/Actions/Email2FA.php b/src/Authentication/Actions/Email2FA.php index fc0958441..1d1e69c1c 100644 --- a/src/Authentication/Actions/Email2FA.php +++ b/src/Authentication/Actions/Email2FA.php @@ -94,7 +94,7 @@ public function handle(IncomingRequest $request) $email->setSubject(lang('Auth.email2FASubject')); $email->setMessage($this->view( setting('Auth.views')['action_email_2fa_email'], - ['code' => $identity->secret, 'ipAddress' => $ipAddress, 'userAgent' => $userAgent, 'date' => $date], + ['code' => $identity->secret, 'user' => $user, 'ipAddress' => $ipAddress, 'userAgent' => $userAgent, 'date' => $date], ['debug' => false] )); diff --git a/src/Authentication/Actions/EmailActivator.php b/src/Authentication/Actions/EmailActivator.php index 2dd14d5e6..2b47f374e 100644 --- a/src/Authentication/Actions/EmailActivator.php +++ b/src/Authentication/Actions/EmailActivator.php @@ -71,7 +71,7 @@ public function show(): string $email->setSubject(lang('Auth.emailActivateSubject')); $email->setMessage($this->view( setting('Auth.views')['action_email_activate_email'], - ['code' => $code, 'ipAddress' => $ipAddress, 'userAgent' => $userAgent, 'date' => $date], + ['code' => $code, 'user' => $user, 'ipAddress' => $ipAddress, 'userAgent' => $userAgent, 'date' => $date], ['debug' => false] )); diff --git a/src/Controllers/MagicLinkController.php b/src/Controllers/MagicLinkController.php index 1558c6843..39ae12866 100644 --- a/src/Controllers/MagicLinkController.php +++ b/src/Controllers/MagicLinkController.php @@ -127,7 +127,7 @@ public function loginAction() $email->setSubject(lang('Auth.magicLinkSubject')); $email->setMessage($this->view( setting('Auth.views')['magic-link-email'], - ['token' => $token, 'ipAddress' => $ipAddress, 'userAgent' => $userAgent, 'date' => $date], + ['token' => $token, 'user' => $user, 'ipAddress' => $ipAddress, 'userAgent' => $userAgent, 'date' => $date], ['debug' => false] )); diff --git a/src/Views/Email/email_2fa_email.php b/src/Views/Email/email_2fa_email.php index c93d8e80c..a4d0273ce 100644 --- a/src/Views/Email/email_2fa_email.php +++ b/src/Views/Email/email_2fa_email.php @@ -23,6 +23,7 @@ +

: username) ?>

diff --git a/src/Views/Email/email_activate_email.php b/src/Views/Email/email_activate_email.php index 7fb63dc95..a6a2cbadd 100644 --- a/src/Views/Email/email_activate_email.php +++ b/src/Views/Email/email_activate_email.php @@ -23,6 +23,7 @@ +

: username) ?>

diff --git a/src/Views/Email/magic_link_email.php b/src/Views/Email/magic_link_email.php index c93ed76bc..4f2d449ba 100644 --- a/src/Views/Email/magic_link_email.php +++ b/src/Views/Email/magic_link_email.php @@ -28,6 +28,7 @@ +

: username) ?>

diff --git a/tests/Controllers/ActionsTest.php b/tests/Controllers/ActionsTest.php index f44d5fc44..ee8650122 100644 --- a/tests/Controllers/ActionsTest.php +++ b/tests/Controllers/ActionsTest.php @@ -134,6 +134,9 @@ public function testEmail2FAHandleSendsEmail(): void // Should have sent an email with the code.... $this->assertStringContainsString('Your authentication code is:', service('email')->archive['body']); + + // Should have included the username in the email + $this->assertStringContainsString($this->user->username, service('email')->archive['body']); } public function testEmail2FAVerifyFails(): void @@ -248,6 +251,9 @@ public function testEmailActivateShow(): void '!

[0-9]{6}

!', service('email')->archive['body'] ); + + // Should have included the username in the email + $this->assertStringContainsString($this->user->username, service('email')->archive['body']); } public function testEmailActivateVerify(): void