Skip to content

Commit

Permalink
[TASK] Replace flogin email templates by core
Browse files Browse the repository at this point in the history
  • Loading branch information
Lacr1ma committed Oct 4, 2021
1 parent b54f5ff commit ee55045
Show file tree
Hide file tree
Showing 29 changed files with 183 additions and 698 deletions.
41 changes: 17 additions & 24 deletions Classes/Notification/AbstractNotificationSender.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php
/** @noinspection PhpUnhandledExceptionInspection */

declare(strict_types = 1);

namespace LMS\Flogin\Notification;
Expand Down Expand Up @@ -26,50 +28,41 @@
* This copyright notice MUST APPEAR in all copies of the script!
* ************************************************************* */

use TYPO3\CMS\Core\Mail\Mailer;
use LMS\Flogin\Support\TypoScript;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Mail\MailMessage;
use LMS\Flogin\Support\Helper\HtmlView;
use TYPO3\CMS\Core\Mail\FluidEmail;
use Symfony\Component\Mime\Address;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
use TijsVerkoyen\CssToInlineStyles\CssToInlineStyles;

/**
* @author Sergey Borulko <borulkosergey@icloud.com>
*/
abstract class AbstractNotificationSender
{
use HtmlView;

protected MailMessage $mail;
protected Mailer $mailer;

public function __construct(MailMessage $message)
public function __construct(Mailer $mailer)
{
$this->mail = $message;
$this->mailer = $mailer;
}

/**
* Sends the email to proper location based on abstract functions
*/
protected function sendViaMail(array $receiver, array $variables = []): void
{
$view = $this->getExtensionView($this->getTemplateSuffix(), $variables);
$html = $this->applyStyles($view->render());

$this->mail
->setSubject($this->getSubject())
->setTo($receiver)
->html($html)
->send();
}

protected function applyStyles(string $html): string
{
$css = GeneralUtility::makeInstance(CssToInlineStyles::class);
$to = new Address(array_key_first($receiver) ?: '', array_shift($receiver));

$cssPath = Environment::getPublicPath() . '/' . $this->getSettings()['stylesPath'];
$mail = GeneralUtility::makeInstance(FluidEmail::class)
->to($to)
->format('html')
->subject($this->getSubject())
->setTemplate($this->getTemplateSuffix())
->assign('data', $variables)
->assign('headline', $this->getSubject());

return $css->convert($html, file_get_contents($cssPath));
$this->mailer->send($mail);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Classes/Slot/Notification/LockoutNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@ protected function getSubject(): string
*/
protected function getTemplateSuffix(): string
{
return 'Email/Lockout';
return 'Lockout';
}
}
2 changes: 1 addition & 1 deletion Classes/Slot/Notification/LoginNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,6 @@ protected function getSubject(): string
*/
protected function getTemplateSuffix(): string
{
return 'Email/Login';
return 'Login';
}
}
2 changes: 1 addition & 1 deletion Classes/Slot/Notification/MagicLinkNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@ protected function getSubject(): string
*/
protected function getTemplateSuffix(): string
{
return 'Email/MagicLink';
return 'MagicLink';
}
}
2 changes: 1 addition & 1 deletion Classes/Slot/Notification/PasswordChangedNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@ protected function getSubject(): string
*/
protected function getTemplateSuffix(): string
{
return 'Email/Password/Changed';
return 'Password/Changed';
}
}
2 changes: 1 addition & 1 deletion Classes/Slot/Notification/ResetPasswordNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@ protected function getSubject(): string
*/
protected function getTemplateSuffix(): string
{
return 'Email/Password/ResetRequest';
return 'Password/ResetRequest';
}
}
40 changes: 0 additions & 40 deletions Configuration/Commands.php

This file was deleted.

6 changes: 5 additions & 1 deletion Configuration/TCA/Overrides/sys_template.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,8 @@

use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;

ExtensionManagementUtility::addStaticFile('flogin', 'Configuration/TypoScript', 'LMS: Login');
ExtensionManagementUtility::addStaticFile(
'flogin',
'Configuration/TypoScript',
'LMS: Login'
);
9 changes: 0 additions & 9 deletions Configuration/TypoScript/Constants/Settings/email.typoscript
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
plugin.tx_flogin.settings.email {

# cat=plugin.tx_flogin//a; type=string; label=Used inside the bottom area of the mail. Basically link to owner website.
site = https://typo3.org

# cat=plugin.tx_flogin//a; type=string; label=Full path to the logo image.
logoPath = EXT:flogin/Resources/Public/Icons/Logo.svg

# cat=plugin.tx_flogin//a; type=string; label=Full path to the css file that should be connected in email
stylesPath = typo3conf/ext/flogin/Resources/Public/Css/Email.css

magicLink {
# cat=plugin.tx_flogin//a; type=string; label=Translation file path with key, that contains subject for magic link notification.
subject = LLL:EXT:flogin/Resources/Private/Language/email.xlf:magic_link.subject
Expand Down
4 changes: 0 additions & 4 deletions Configuration/TypoScript/Setup/settings.typoscript
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ plugin.tx_flogin.settings {
}

email {
site = {$plugin.tx_flogin.settings.email.site}
logoPath = {$plugin.tx_flogin.settings.email.logoPath}
stylesPath = {$plugin.tx_flogin.settings.email.stylesPath}

magicLink {
subject = {$plugin.tx_flogin.settings.email.magicLink.subject}
linkLifetimeInMinutes = {$plugin.tx_flogin.settings.email.magicLink.linkLifetimeInMinutes}
Expand Down
95 changes: 0 additions & 95 deletions Resources/Private/Layouts/Email.html

This file was deleted.

73 changes: 21 additions & 52 deletions Resources/Private/Templates/Email/Lockout.html
Original file line number Diff line number Diff line change
@@ -1,55 +1,24 @@
<f:layout name="Email"/>
<f:layout name="SystemEmail" />

<f:section name="Header">
<img src="{f:uri.image(src: '{email.logoPath}', absolute: 1)}" class="logo" width="250"/>
</f:section>
<f:section name="Title">{headline}</f:section>

<f:section name="Main">
<table width="100%" cellspacing="0" cellpadding="0" bgcolor="#fcfcfc">

<tr>
<td class="es-m-txt-c" align="center">
<h2>
<strong>
<f:translate key="LLL:EXT:flogin/Resources/Private/Language/email.xlf:lockout.caption"/>
</strong>
</h2>
</td>
</tr>

<tr>
<td class="es-m-txt-l" bgcolor="transparent" align="left">
<span>
<f:translate arguments="{0: '{user.lockMinutesInterval}'}" key="LLL:EXT:flogin/Resources/Private/Language/email.xlf:lockout.caption_description"/>
</span>
</td>
</tr>

<tr>
<td align="center" class="es-m-txt-c">
<span class="es-button-border">
<f:cache.disable>
<a href="{user.unlockActionUrl}" class="es-button" target="_blank">
<f:translate key="LLL:EXT:flogin/Resources/Private/Language/email.xlf:lockout.button_unlock"/>
</a>
</f:cache.disable>
</span>
</td>
</tr>

<tr>
<td class="es-m-txt-l" bgcolor="transparent" align="left">
<span>
<f:translate key="LLL:EXT:flogin/Resources/Private/Language/email.xlf:lockout.help"/>
</span>
</td>
</tr>

</table>
</f:section>

<f:section name="Footer">
<f:format.raw>
<f:translate arguments="{0: '{email.site}'}" key="LLL:EXT:flogin/Resources/Private/Language/email.xlf:common.signature"/>
</f:format.raw>
</f:section>
<h3>
<f:translate key="LLL:EXT:flogin/Resources/Private/Language/email.xlf:lockout.caption"/>
</h3>

<p>
<f:translate arguments="{0: '{data.user.lockMinutesInterval}'}" key="LLL:EXT:flogin/Resources/Private/Language/email.xlf:lockout.caption_description"/>

<f:cache.disable>
<a href="{data.user.unlockActionUrl}" class="es-button" target="_blank">
<f:translate key="LLL:EXT:flogin/Resources/Private/Language/email.xlf:lockout.button_unlock"/>
</a>
</f:cache.disable>
<br/>
</p>

<p>
<f:translate key="LLL:EXT:flogin/Resources/Private/Language/email.xlf:lockout.help"/>
</p>
</f:section>
Loading

0 comments on commit ee55045

Please sign in to comment.