diff --git a/typo3/sysext/install/Classes/Authentication/AuthenticationService.php b/typo3/sysext/install/Classes/Authentication/AuthenticationService.php index 80bf5645e806f202a3083c576b37fb8859bc1e48..f6dd5c09a5901abf992eb34cbde488f11105cba0 100644 --- a/typo3/sysext/install/Classes/Authentication/AuthenticationService.php +++ b/typo3/sysext/install/Classes/Authentication/AuthenticationService.php @@ -15,12 +15,14 @@ namespace TYPO3\CMS\Install\Authentication; * The TYPO3 project - inspiring people to share! */ +use Psr\Http\Message\ServerRequestInterface; use Symfony\Component\Mime\Address; use TYPO3\CMS\Core\Crypto\PasswordHashing\PasswordHashFactory; use TYPO3\CMS\Core\Mail\FluidEmail; use TYPO3\CMS\Core\Mail\Mailer; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Core\Utility\MailUtility; +use TYPO3\CMS\Fluid\View\TemplatePaths; use TYPO3\CMS\Install\Service\SessionService; /** @@ -34,21 +36,30 @@ class AuthenticationService */ protected $sessionService; + /** + * @var TemplatePaths + */ + protected $templatePaths; + /** * @param SessionService $sessionService */ public function __construct(SessionService $sessionService) { $this->sessionService = $sessionService; + $templateConfiguration = $GLOBALS['TYPO3_CONF_VARS']['MAIL']; + $templateConfiguration['templateRootPaths'][20] = 'EXT:install/Resources/Private/Templates/Email/'; + $this->templatePaths = new TemplatePaths($templateConfiguration); } /** * Checks against a given password * - * @param string $password + * @param string|null $password + * @param ServerRequestInterface $request * @return bool if authentication was successful, otherwise false */ - public function loginWithPassword($password = null): bool + public function loginWithPassword($password, ServerRequestInterface $request): bool { $validPassword = false; if ($password !== null && $password !== '') { @@ -61,48 +72,54 @@ class AuthenticationService } if ($validPassword) { $this->sessionService->setAuthorized(); - $this->sendLoginSuccessfulMail(); + $this->sendLoginSuccessfulMail($request); return true; } - $this->sendLoginFailedMail(); + $this->sendLoginFailedMail($request); return false; } /** * If install tool login mail is set, send a mail for a successful login. + * + * @param ServerRequestInterface $request */ - protected function sendLoginSuccessfulMail() + protected function sendLoginSuccessfulMail(ServerRequestInterface $request) { $warningEmailAddress = $GLOBALS['TYPO3_CONF_VARS']['BE']['warning_email_addr']; if (!$warningEmailAddress) { return; } - $email = GeneralUtility::makeInstance(FluidEmail::class); + $email = GeneralUtility::makeInstance(FluidEmail::class, $this->templatePaths); $email ->to($warningEmailAddress) ->subject('Install Tool Login at \'' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'] . '\'') ->from(new Address($this->getSenderEmailAddress(), $this->getSenderEmailName())) - ->setTemplate('Security/InstallToolLogin'); + ->setTemplate('Security/InstallToolLogin') + ->setRequest($request); GeneralUtility::makeInstance(Mailer::class)->send($email); } /** * If install tool login mail is set, send a mail for a failed login. + * + * @param ServerRequestInterface $request */ - protected function sendLoginFailedMail() + protected function sendLoginFailedMail(ServerRequestInterface $request) { $warningEmailAddress = $GLOBALS['TYPO3_CONF_VARS']['BE']['warning_email_addr']; if (!$warningEmailAddress) { return; } $formValues = GeneralUtility::_GP('install'); - $email = GeneralUtility::makeInstance(FluidEmail::class); + $email = GeneralUtility::makeInstance(FluidEmail::class, $this->templatePaths); $email ->to($warningEmailAddress) ->subject('Install Tool Login ATTEMPT at \'' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'] . '\'') ->from(new Address($this->getSenderEmailAddress(), $this->getSenderEmailName())) ->setTemplate('Security/InstallToolLoginAttempt') - ->assign('lastCharactersOfPassword', substr(md5($formValues['password']), -5)); + ->assign('lastCharactersOfPassword', substr(md5($formValues['password']), -5)) + ->setRequest($request); GeneralUtility::makeInstance(Mailer::class)->send($email); } diff --git a/typo3/sysext/install/Classes/Middleware/Maintenance.php b/typo3/sysext/install/Classes/Middleware/Maintenance.php index a850ec9da2d259c57429eda9f17ae08a250b9638..39ac8178d009e00491aa3d909c48973c76133a7e 100644 --- a/typo3/sysext/install/Classes/Middleware/Maintenance.php +++ b/typo3/sysext/install/Classes/Middleware/Maintenance.php @@ -159,7 +159,7 @@ class Maintenance implements MiddlewareInterface $this->checkSessionLifetime($session); $password = $request->getParsedBody()['install']['password'] ?? null; $authService = new AuthenticationService($session); - if ($authService->loginWithPassword($password)) { + if ($authService->loginWithPassword($password, $request)) { $response = new JsonResponse([ 'success' => true, ]);