Update HTML 2FA template

Split paragraph in translation
Inject wallabag_url for image in HTML template
Remove username & password from config_dev.yml (null are already the default value)
This commit is contained in:
Jeremy Benoist 2016-01-20 17:43:10 +01:00
parent 5f736213af
commit abd454c456
7 changed files with 51 additions and 39 deletions

View file

@ -42,6 +42,3 @@ swiftmailer:
transport: smtp transport: smtp
host: 'localhost' host: 'localhost'
port: 1025 port: 1025
username: null
password: null

View file

@ -46,6 +46,13 @@ class AuthCodeMailer implements AuthCodeMailerInterface
*/ */
private $supportUrl; private $supportUrl;
/**
* Url for the wallabag instance.
*
* @var string
*/
private $wallabagUrl;
/** /**
* Initialize the auth code mailer with the SwiftMailer object. * Initialize the auth code mailer with the SwiftMailer object.
* *
@ -54,14 +61,16 @@ class AuthCodeMailer implements AuthCodeMailerInterface
* @param string $senderEmail * @param string $senderEmail
* @param string $senderName * @param string $senderName
* @param string $supportUrl * @param string $supportUrl
* @param string $wallabagUrl
*/ */
public function __construct(\Swift_Mailer $mailer, \Twig_Environment $twig, $senderEmail, $senderName, $supportUrl) public function __construct(\Swift_Mailer $mailer, \Twig_Environment $twig, $senderEmail, $senderName, $supportUrl, $wallabagUrl)
{ {
$this->mailer = $mailer; $this->mailer = $mailer;
$this->twig = $twig; $this->twig = $twig;
$this->senderEmail = $senderEmail; $this->senderEmail = $senderEmail;
$this->senderName = $senderName; $this->senderName = $senderName;
$this->supportUrl = $supportUrl; $this->supportUrl = $supportUrl;
$this->wallabagUrl = $wallabagUrl;
} }
/** /**
@ -77,12 +86,13 @@ class AuthCodeMailer implements AuthCodeMailerInterface
$bodyHtml = $template->renderBlock('body_html', [ $bodyHtml = $template->renderBlock('body_html', [
'user' => $user->getName(), 'user' => $user->getName(),
'code' => $user->getEmailAuthCode(), 'code' => $user->getEmailAuthCode(),
'support' => $this->supportUrl, 'support_url' => $this->supportUrl,
'wallabag_url' => $this->wallabagUrl,
]); ]);
$bodyText = $template->renderBlock('body_text', [ $bodyText = $template->renderBlock('body_text', [
'user' => $user->getName(), 'user' => $user->getName(),
'code' => $user->getEmailAuthCode(), 'code' => $user->getEmailAuthCode(),
'support' => $this->supportUrl, 'support_url' => $this->supportUrl,
]); ]);
$message = new \Swift_Message(); $message = new \Swift_Message();

View file

@ -7,3 +7,4 @@ services:
- "%scheb_two_factor.email.sender_email%" - "%scheb_two_factor.email.sender_email%"
- "%scheb_two_factor.email.sender_name%" - "%scheb_two_factor.email.sender_name%"
- "%wallabag_support_url%" - "%wallabag_support_url%"
- "%wallabag_url%"

View file

@ -1,9 +1,7 @@
# Two factor mail # Two factor mail
auth_code.mailer.subject: 'Wallabag authentication Code' auth_code.mailer.subject: 'Wallabag authentication Code'
auth_code.mailer.body.hello: "Hi %user%," auth_code.mailer.body.hello: "Hi %user%,"
auth_code.mailer.body.content: | auth_code.mailer.body.first_para: "Since you enable two factor authentication on your wallabag account and you just logged in from a new device (computer, phone, etc.), we send you a code to validate your connection."
Since you enable two factor authentication on your wallabag account and you just logged in from a new device (computer, phone, etc.), we send you a code to validate your connection. auth_code.mailer.body.second_para: "Here is the code:"
Here is the code: %code% auth_code.mailer.body.support: "Please don't hesitate to contact us if you have any problems:"
auth_code.mailer.body.signature: | auth_code.mailer.body.signature: "The wallabag team"
Please don't hesitate to contact us if you have any problems: %support%
The wallabag team

View file

@ -1,9 +1,7 @@
# Two factor mail # Two factor mail
auth_code.mailer.subject: "Code d'authentification wallabag" auth_code.mailer.subject: "Code d'authentification wallabag"
auth_code.mailer.body.hello: "Bonjour %user%," auth_code.mailer.body.hello: "Bonjour %user%,"
auth_code.mailer.body.content: | auth_code.mailer.body.first_para: "Comme vous avez activé la double authentification sur votre compte wallabag et que vous venez de vous connecter depuis un nouvel appareil (ordinateur, téléphone, etc.), nous vous envoyons un code pour valider votre connexion."
Comme vous avez activé la double authentification sur votre compte wallabag et que vous venez de vous connecter depuis un nouvel appareil (ordinateur, téléphone, etc.), nous vous envoyons un code pour valider votre connexion. auth_code.mailer.body.second_para: "Voici le code à renseigner :"
Voici le code à renseigner: %code% auth_code.mailer.body.support: "Si vous avez un problème de connexion, n'hésitez pas à contacter le support :"
auth_code.mailer.body.signature: | auth_code.mailer.body.signature: "L'équipe wallabag"
Si vous avez un problème de connexion, n'hésitez pas à contacter le support: %support%
L'équipe wallabag

View file

@ -2,6 +2,17 @@
{{ "auth_code.mailer.subject"|trans({}, 'wallabag_user') }} {{ "auth_code.mailer.subject"|trans({}, 'wallabag_user') }}
{% endblock %} {% endblock %}
{% block body_text %}
{{ "auth_code.mailer.body.hello"|trans({'%user%': user}, 'wallabag_user') }}
{{ "auth_code.mailer.body.first_para"|trans({}, 'wallabag_user') }}
{{ "auth_code.mailer.body.second_para"|trans({}, 'wallabag_user') }} {{ code }}
{{ "auth_code.mailer.body.support"|trans({}, 'wallabag_user') }} {{ support_url }}
{{ "auth_code.mailer.body.signature"|trans({}, 'wallabag_user') }}
{% endblock %}
{% block body_html %} {% block body_html %}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
@ -63,10 +74,10 @@
<table cellpadding="0" cellspacing="0" border="0" align="center" id="card"> <table cellpadding="0" cellspacing="0" border="0" align="center" id="card">
<tr> <tr>
<td style="padding: 20px;" width="96px" valign="top"><img class="image_fix" src="{ wallabag_url }/themes/material/img/logo-other_themes.png" alt="logo" title="{ wallabag_url }" style="width: 96px; height: 96px;" /></td> <td style="padding: 20px;" width="96px" valign="top"><img class="image_fix" src="{{ wallabag_url }}/themes/material/img/logo-other_themes.png" alt="logo" title="{{ wallabag_url }}" style="width: 96px; height: 96px;" /></td>
<td style="padding: 20px; padding-left: 0;" valign="top" id="cell_desc"> <td style="padding: 20px; padding-left: 0;" valign="top" id="cell_desc">
<h1>Wallabag</h1> <h1>wallabag</h1>
<h5>{% trans %}on{% endtrans %} { wallabag_url }</h5> <h5>{% trans %}on{% endtrans %} {{ wallabag_url }}</h5>
</td> </td>
</tr> </tr>
<tr><td colspan="2" style="padding: 0;"><div style="height: 0; border-top: 1px solid #c5c5c5;">&nbsp;</div></td></tr> <tr><td colspan="2" style="padding: 0;"><div style="height: 0; border-top: 1px solid #c5c5c5;">&nbsp;</div></td></tr>
@ -75,10 +86,11 @@
<p><b>{{ "auth_code.mailer.body.hello"|trans({'%user%': user}, 'wallabag_user') }}</b></p> <p><b>{{ "auth_code.mailer.body.hello"|trans({'%user%': user}, 'wallabag_user') }}</b></p>
<p>{{ "auth_code.mailer.body.content"|trans({'%code%': code}, 'wallabag_user') }}</p> <p>{{ "auth_code.mailer.body.first_para"|trans({}, 'wallabag_user') }}</p>
<p>{{ "auth_code.mailer.body.second_para"|trans({}, 'wallabag_user') }} <b>{{ code }}</b></p>
<p>{{ "auth_code.mailer.body.signature"|trans({'%support%': support}, 'wallabag_user') }}</p>
<p>{{ "auth_code.mailer.body.support"|trans({}, 'wallabag_user') }} <a href="{{ support_url }}">{{ support_url }}</a></p>
<p>{{ "auth_code.mailer.body.signature"|trans({}, 'wallabag_user') }}</p>
</td> </td>
</tr> </tr>
<tr><td colspan="2" style="padding: 0;"><div style="height: 0; border-top: 1px solid #c5c5c5;">&nbsp;</div></td></tr> <tr><td colspan="2" style="padding: 0;"><div style="height: 0; border-top: 1px solid #c5c5c5;">&nbsp;</div></td></tr>
@ -87,8 +99,8 @@
<table cellpadding="0" cellspacing="0" border="0" width="100%"> <table cellpadding="0" cellspacing="0" border="0" width="100%">
<tr> <tr>
<td valign="top" style="padding: 20px; text-align: center"><a href="{ wallabag_url }">{ wallabag_url }</a></td> <td valign="top" style="padding: 20px; text-align: center"><a href="{{ wallabag_url }}">{{ wallabag_url }}</a></td>
<td valign="top" style="padding: 20px; text-align: center">Powered by <a href="https://www.wallabag.org/">Wallabag</a></td> <td valign="top" style="padding: 20px; text-align: center">Powered by <a href="https://www.wallabag.org/">wallabag</a></td>
</tr> </tr>
</table> </table>
@ -103,10 +115,3 @@
</body> </body>
</html> </html>
{% endblock %} {% endblock %}
{% block body_text %}
{{ "auth_code.mailer.body.hello"|trans({'%user%': user}, 'wallabag_user') }}
{{ "auth_code.mailer.body.content"|trans({'%code%': code}, 'wallabag_user') }}
{{ "auth_code.mailer.body.signature"|trans({'%support%': support}, 'wallabag_user') }}
{% endblock %}

View file

@ -36,11 +36,13 @@ class AuthCodeMailerTest extends \PHPUnit_Framework_TestCase
); );
$this->mailer = new \Swift_Mailer($transport); $this->mailer = new \Swift_Mailer($transport);
$this->twig = new \Twig_Environment(new \Twig_Loader_Array(array('@WallabagUserBundle/Resources/views/TwoFactor/email_auth_code.html.twig' => ' $twigTemplate = <<<TWIG
{% block subject %}subject{% endblock %} {% block subject %}subject{% endblock %}
{% block body_html %}html body{% endblock %} {% block body_html %}html body {{ code }}{% endblock %}
{% block body_text %}text body{% endblock %} {% block body_text %}text body {{ support_url }}{% endblock %}
'))); TWIG;
$this->twig = new \Twig_Environment(new \Twig_Loader_Array(array('@WallabagUserBundle/Resources/views/TwoFactor/email_auth_code.html.twig' => $twigTemplate)));
} }
public function testSendEmail() public function testSendEmail()
@ -56,6 +58,7 @@ class AuthCodeMailerTest extends \PHPUnit_Framework_TestCase
$this->twig, $this->twig,
'nobody@test.io', 'nobody@test.io',
'wallabag test', 'wallabag test',
'http://0.0.0.0/support',
'http://0.0.0.0' 'http://0.0.0.0'
); );
@ -67,7 +70,7 @@ class AuthCodeMailerTest extends \PHPUnit_Framework_TestCase
$this->assertArrayHasKey('test@wallabag.io', $msg->getTo()); $this->assertArrayHasKey('test@wallabag.io', $msg->getTo());
$this->assertEquals(array('nobody@test.io' => 'wallabag test'), $msg->getFrom()); $this->assertEquals(array('nobody@test.io' => 'wallabag test'), $msg->getFrom());
$this->assertEquals('subject', $msg->getSubject()); $this->assertEquals('subject', $msg->getSubject());
$this->assertContains('text body', $msg->toString()); $this->assertContains('text body http://0.0.0.0/support', $msg->toString());
$this->assertContains('html body', $msg->toString()); $this->assertContains('html body 666666', $msg->toString());
} }
} }