From 7aff38442f2079358a93fea0a668191398414b79 Mon Sep 17 00:00:00 2001 From: Peter Umoren Date: Fri, 7 Jun 2024 03:22:24 +0100 Subject: [PATCH 1/3] chore: Update email templates with user information --- src/Authentication/Actions/Email2FA.php | 2 +- src/Authentication/Actions/EmailActivator.php | 2 +- src/Controllers/MagicLinkController.php | 2 +- src/Views/Email/email_2fa_email.php | 3 ++- src/Views/Email/email_activate_email.php | 1 + src/Views/Email/magic_link_email.php | 3 ++- 6 files changed, 8 insertions(+), 5 deletions(-) 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..64be17d88 100644 --- a/src/Views/Email/email_2fa_email.php +++ b/src/Views/Email/email_2fa_email.php @@ -23,9 +23,10 @@ +

: username) ?>

- + \ No newline at end of file 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..e111dedf9 100644 --- a/src/Views/Email/magic_link_email.php +++ b/src/Views/Email/magic_link_email.php @@ -28,9 +28,10 @@ +

: username) ?>

- + \ No newline at end of file From 5f9b4e208d823997bd9a9b184dd2d2051ca16d58 Mon Sep 17 00:00:00 2001 From: Peter Umoren Date: Thu, 13 Jun 2024 12:42:54 +0100 Subject: [PATCH 2/3] chore: Enhance email tests to validate presence of username. --- src/Views/Email/email_2fa_email.php | 2 +- src/Views/Email/magic_link_email.php | 2 +- tests/Controllers/ActionsTest.php | 6 ++++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Views/Email/email_2fa_email.php b/src/Views/Email/email_2fa_email.php index 64be17d88..a4d0273ce 100644 --- a/src/Views/Email/email_2fa_email.php +++ b/src/Views/Email/email_2fa_email.php @@ -29,4 +29,4 @@

- \ No newline at end of file + diff --git a/src/Views/Email/magic_link_email.php b/src/Views/Email/magic_link_email.php index e111dedf9..4f2d449ba 100644 --- a/src/Views/Email/magic_link_email.php +++ b/src/Views/Email/magic_link_email.php @@ -34,4 +34,4 @@

- \ No newline at end of file + 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 From 2c806edc0c8f604fbadeb509a2c9d0209d72c2b5 Mon Sep 17 00:00:00 2001 From: Peter Umoren Date: Thu, 13 Jun 2024 14:38:55 +0100 Subject: [PATCH 3/3] chore: Updated the instructions for customizing email templates --- docs/customization/views.md | 2 ++ 1 file changed, 2 insertions(+) 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.