Commit 3dac41ff authored by Benni Mack's avatar Benni Mack Committed by Frank Nägler
Browse files

[TASK] Allow subject to be handled in EmailLoginNotification

The subject can also be defined in a templated email. This way,
it is possible to allow custom subjects and completely modify
the login notification email.

Resolves: #90423
Releases: master
Change-Id: Idc904c8f06a7ffc2e491a2eb283ae6ba8f9dc00b
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/63313


Tested-by: Susanne Moog's avatarSusanne Moog <look@susi.dev>
Tested-by: Daniel Goerz's avatarDaniel Goerz <daniel.goerz@posteo.de>
Tested-by: Frank Nägler's avatarFrank Nägler <frank.naegler@typo3.org>
Reviewed-by: Susanne Moog's avatarSusanne Moog <look@susi.dev>
Reviewed-by: Daniel Goerz's avatarDaniel Goerz <daniel.goerz@posteo.de>
Reviewed-by: Frank Nägler's avatarFrank Nägler <frank.naegler@typo3.org>
parent 6f136584
......@@ -93,15 +93,18 @@ class EmailLoginNotification
*/
protected function sendEmail(string $recipient, AbstractUserAuthentication $user, string $subjectPrefix = null): void
{
$subject = $subjectPrefix . ' New TYPO3 Login at "' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'] . '" from ' . GeneralUtility::getIndpEnv('REMOTE_ADDR');
$headline = 'TYPO3 Backend Login notification';
$recipients = explode(',', $recipient);
$email = GeneralUtility::makeInstance(FluidEmail::class)
->to(...$recipients)
->subject($subject)
->setRequest($this->request)
->setTemplate('Security/LoginNotification')
->assignMultiple(['user' => $user->user, 'headline' => $headline]);
->assignMultiple([
'user' => $user->user,
'prefix' => $subjectPrefix,
'language' => $user->uc['lang'] ?? 'default',
'headline' => $headline
]);
GeneralUtility::makeInstance(Mailer::class)->send($email);
}
}
<f:layout name="SystemEmail" />
<f:section name="Subject">{prefix} New Login at "{typo3.sitename}"</f:section>
<f:section name="Title">{headline}</f:section>
<f:section name="Main">
<h4>{introduction}</h4>
......
<f:layout name="SystemEmail" />
<f:section name="Subject">{prefix} New Login at "{typo3.sitename}"</f:section>
<f:section name="Title">{headline}</f:section>
<f:section name="Main">{introduction}
The user "{user.username}" logged in from the IP address "{normalizedParams.remoteAddress}" at the site "{typo3.sitename}".
......
......@@ -128,7 +128,6 @@ class EmailLoginNotificationTest extends UnitTestCase
$subject->emailAtLogin(['user' => $userData], $backendUser);
$mailMessage->to('typo3-admin@acme.com')->shouldHaveBeenCalled();
$mailMessage->subject('[AdminLoginWarning] New TYPO3 Login at "My TYPO3 Inc." from 127.0.0.1')->shouldHaveBeenCalled();
}
/**
......@@ -158,7 +157,6 @@ class EmailLoginNotificationTest extends UnitTestCase
$subject = new EmailLoginNotification();
$subject->emailAtLogin(['user' => $userData], $backendUser);
$mailMessage->subject('[AdminLoginWarning] New TYPO3 Login at "My TYPO3 Inc." from 127.0.0.1')->shouldHaveBeenCalled();
$mailMessage->to('typo3-admin@acme.com')->shouldHaveBeenCalled();
}
......@@ -190,7 +188,6 @@ class EmailLoginNotificationTest extends UnitTestCase
$subject->emailAtLogin(['user' => $userData], $backendUser);
$mailMessage->to('typo3-admin@acme.com')->shouldHaveBeenCalled();
$mailMessage->subject('[LoginWarning] New TYPO3 Login at "My TYPO3 Inc." from 127.0.0.1')->shouldHaveBeenCalled();
}
/**
......@@ -224,7 +221,6 @@ class EmailLoginNotificationTest extends UnitTestCase
protected function setUpMailMessageProphecy()
{
$mailMessage = $this->prophesize(FluidEmail::class);
$mailMessage->subject(Argument::any())->willReturn($mailMessage->reveal());
$mailMessage->to(Argument::any())->willReturn($mailMessage->reveal());
$mailMessage->setTemplate(Argument::any())->willReturn($mailMessage->reveal());
$mailMessage->from(Argument::any())->willReturn($mailMessage->reveal());
......
......@@ -31,6 +31,8 @@ set this in your LocalConfiguration.php / AdditionalConfiguration.php file:
* :php:`$GLOBALS['TYPO3_CONF_VARS']['MAIL']['templateRootPaths'][700] = 'EXT:my_site_extension/Resources/Private/Templates/Email';`
* :php:`$GLOBALS['TYPO3_CONF_VARS']['MAIL']['layoutRootPaths'][700] = 'EXT:my_site_extension/Resources/Private/Layouts';`
In addition, it is possible to define a section within the Fluid email,
which - if defined - takes precedence over the :php:`subject()` method.
In addition, it is possible to define a section within the Fluid email,
which - if set - takes precedence over the :php:`subject()` method.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment