Skip to content

Commit 4507f1b

Browse files
authored
Merge pull request #1125 from pmagictech/develop
feat: Updated email templates with user information
2 parents 22a8b3b + 2c806ed commit 4507f1b

File tree

8 files changed

+14
-3
lines changed

8 files changed

+14
-3
lines changed

docs/customization/views.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,5 @@ to the **app/Views/Shield/** folder.
3737
## Customize Content
3838

3939
Customize the content of the view file in **app/Views/Shield/** as you like.
40+
41+
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.

src/Authentication/Actions/Email2FA.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public function handle(IncomingRequest $request)
9494
$email->setSubject(lang('Auth.email2FASubject'));
9595
$email->setMessage($this->view(
9696
setting('Auth.views')['action_email_2fa_email'],
97-
['code' => $identity->secret, 'ipAddress' => $ipAddress, 'userAgent' => $userAgent, 'date' => $date],
97+
['code' => $identity->secret, 'user' => $user, 'ipAddress' => $ipAddress, 'userAgent' => $userAgent, 'date' => $date],
9898
['debug' => false]
9999
));
100100

src/Authentication/Actions/EmailActivator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function show(): string
7171
$email->setSubject(lang('Auth.emailActivateSubject'));
7272
$email->setMessage($this->view(
7373
setting('Auth.views')['action_email_activate_email'],
74-
['code' => $code, 'ipAddress' => $ipAddress, 'userAgent' => $userAgent, 'date' => $date],
74+
['code' => $code, 'user' => $user, 'ipAddress' => $ipAddress, 'userAgent' => $userAgent, 'date' => $date],
7575
['debug' => false]
7676
));
7777

src/Controllers/MagicLinkController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public function loginAction()
127127
$email->setSubject(lang('Auth.magicLinkSubject'));
128128
$email->setMessage($this->view(
129129
setting('Auth.views')['magic-link-email'],
130-
['token' => $token, 'ipAddress' => $ipAddress, 'userAgent' => $userAgent, 'date' => $date],
130+
['token' => $token, 'user' => $user, 'ipAddress' => $ipAddress, 'userAgent' => $userAgent, 'date' => $date],
131131
['debug' => false]
132132
));
133133

src/Views/Email/email_2fa_email.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
</tbody>
2424
</table>
2525
<b><?= lang('Auth.emailInfo') ?></b>
26+
<p><?= lang('Auth.username') ?>: <?= esc($user->username) ?></p>
2627
<p><?= lang('Auth.emailIpAddress') ?> <?= esc($ipAddress) ?></p>
2728
<p><?= lang('Auth.emailDevice') ?> <?= esc($userAgent) ?></p>
2829
<p><?= lang('Auth.emailDate') ?> <?= esc($date) ?></p>

src/Views/Email/email_activate_email.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
</tbody>
2424
</table>
2525
<b><?= lang('Auth.emailInfo') ?></b>
26+
<p><?= lang('Auth.username') ?>: <?= esc($user->username) ?></p>
2627
<p><?= lang('Auth.emailIpAddress') ?> <?= esc($ipAddress) ?></p>
2728
<p><?= lang('Auth.emailDevice') ?> <?= esc($userAgent) ?></p>
2829
<p><?= lang('Auth.emailDate') ?> <?= esc($date) ?></p>

src/Views/Email/magic_link_email.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
</tbody>
2929
</table>
3030
<b><?= lang('Auth.emailInfo') ?></b>
31+
<p><?= lang('Auth.username') ?>: <?= esc($user->username) ?></p>
3132
<p><?= lang('Auth.emailIpAddress') ?> <?= esc($ipAddress) ?></p>
3233
<p><?= lang('Auth.emailDevice') ?> <?= esc($userAgent) ?></p>
3334
<p><?= lang('Auth.emailDate') ?> <?= esc($date) ?></p>

tests/Controllers/ActionsTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ public function testEmail2FAHandleSendsEmail(): void
134134

135135
// Should have sent an email with the code....
136136
$this->assertStringContainsString('Your authentication code is:', service('email')->archive['body']);
137+
138+
// Should have included the username in the email
139+
$this->assertStringContainsString($this->user->username, service('email')->archive['body']);
137140
}
138141

139142
public function testEmail2FAVerifyFails(): void
@@ -248,6 +251,9 @@ public function testEmailActivateShow(): void
248251
'!<h1>[0-9]{6}</h1>!',
249252
service('email')->archive['body']
250253
);
254+
255+
// Should have included the username in the email
256+
$this->assertStringContainsString($this->user->username, service('email')->archive['body']);
251257
}
252258

253259
public function testEmailActivateVerify(): void

0 commit comments

Comments
 (0)