diff --git a/app/config/config.yml b/app/config/config.yml index f2538c902..8403a458f 100644 --- a/app/config/config.yml +++ b/app/config/config.yml @@ -198,6 +198,7 @@ scheb_two_factor: sender_email: %twofactor_sender% digits: 6 template: WallabagUserBundle:Authentication:form.html.twig + mailer: wallabag_user.auth_code_mailer kphoen_rulerz: executors: diff --git a/app/config/parameters.yml.dist b/app/config/parameters.yml.dist index b475d6370..149179c2e 100644 --- a/app/config/parameters.yml.dist +++ b/app/config/parameters.yml.dist @@ -52,10 +52,11 @@ parameters: export_mobi: true export_pdf: true wallabag_url: http://v2.wallabag.org + wallabag_support_url: 'https://www.wallabag.org/pages/support.html' # default user config items_on_page: 12 theme: material - language: en_US + language: en from_email: no-reply@wallabag.org rss_limit: 50 diff --git a/app/config/tests/parameters.yml.dist.mysql b/app/config/tests/parameters.yml.dist.mysql index 5b29690c4..096ad8c76 100644 --- a/app/config/tests/parameters.yml.dist.mysql +++ b/app/config/tests/parameters.yml.dist.mysql @@ -52,6 +52,7 @@ parameters: export_mobi: true export_pdf: true wallabag_url: http://v2.wallabag.org + wallabag_support_url: 'https://www.wallabag.org/pages/support.html' # default user config items_on_page: 12 diff --git a/app/config/tests/parameters.yml.dist.pgsql b/app/config/tests/parameters.yml.dist.pgsql index efdac9617..ca3f6ea20 100644 --- a/app/config/tests/parameters.yml.dist.pgsql +++ b/app/config/tests/parameters.yml.dist.pgsql @@ -52,6 +52,7 @@ parameters: export_mobi: true export_pdf: true wallabag_url: http://v2.wallabag.org + wallabag_support_url: 'https://www.wallabag.org/pages/support.html' # default user config items_on_page: 12 diff --git a/app/config/tests/parameters.yml.dist.sqlite b/app/config/tests/parameters.yml.dist.sqlite index 276d11471..92460bcfc 100644 --- a/app/config/tests/parameters.yml.dist.sqlite +++ b/app/config/tests/parameters.yml.dist.sqlite @@ -52,6 +52,7 @@ parameters: export_mobi: true export_pdf: true wallabag_url: http://v2.wallabag.org + wallabag_support_url: 'https://www.wallabag.org/pages/support.html' # default user config items_on_page: 12 diff --git a/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadConfigData.php b/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadConfigData.php index 84b78a89b..3b3c1e979 100644 --- a/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadConfigData.php +++ b/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadConfigData.php @@ -25,7 +25,7 @@ class LoadConfigData extends AbstractFixture implements OrderedFixtureInterface $adminConfig->setTheme('material'); $adminConfig->setItemsPerPage(30); - $adminConfig->setLanguage('en_US'); + $adminConfig->setLanguage('en'); $manager->persist($adminConfig); @@ -34,7 +34,7 @@ class LoadConfigData extends AbstractFixture implements OrderedFixtureInterface $bobConfig = new Config($this->getReference('bob-user')); $bobConfig->setTheme('default'); $bobConfig->setItemsPerPage(10); - $bobConfig->setLanguage('fr_FR'); + $bobConfig->setLanguage('fr'); $manager->persist($bobConfig); diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Config/index.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Config/index.html.twig index cc797c632..d9850f7a9 100644 --- a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Config/index.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Config/index.html.twig @@ -40,6 +40,10 @@ {{ form_start(form.rss) }} {{ form_errors(form.rss) }} +
+ {% trans %}RSS feeds provided by wallabag allow you to read your saved articles with your favourite RSS reader.{% endtrans %} +
+
@@ -101,6 +105,10 @@
{% if twofactor_auth %} +
+ {% trans %}Enabling two factor authentication means you'll receive an email with a code on every new untrusted connexion{% endtrans %} +
+
{{ form_label(form.user.twoFactorAuthentication) }} diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/Config/index.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/Config/index.html.twig index d060311d4..8743dc1dd 100644 --- a/src/Wallabag/CoreBundle/Resources/views/themes/material/Config/index.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/Config/index.html.twig @@ -131,6 +131,12 @@
{% if twofactor_auth %} +
+
+ {% trans %}Enabling two factor authentication means you'll receive an email with a code on every new untrusted connexion{% endtrans %} +
+
+
{{ form_widget(form.user.twoFactorAuthentication) }} diff --git a/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php index 7b32354f8..89ca31e29 100644 --- a/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php +++ b/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php @@ -44,7 +44,7 @@ class ConfigControllerTest extends WallabagCoreTestCase $form = $crawler->filter('button[id=config_save]')->form(); $data = array( - 'config[theme]' => 0, + 'config[theme]' => 'baggy', 'config[items_per_page]' => '30', 'config[language]' => 'en', ); @@ -63,7 +63,7 @@ class ConfigControllerTest extends WallabagCoreTestCase { return array( array(array( - 'config[theme]' => 0, + 'config[theme]' => 'baggy', 'config[items_per_page]' => '', 'config[language]' => 'en', )), diff --git a/src/Wallabag/UserBundle/DependencyInjection/Configuration.php b/src/Wallabag/UserBundle/DependencyInjection/Configuration.php new file mode 100644 index 000000000..4223f8dba --- /dev/null +++ b/src/Wallabag/UserBundle/DependencyInjection/Configuration.php @@ -0,0 +1,17 @@ +root('wallabag_user'); + + return $treeBuilder; + } +} diff --git a/src/Wallabag/UserBundle/DependencyInjection/WallabagUserExtension.php b/src/Wallabag/UserBundle/DependencyInjection/WallabagUserExtension.php new file mode 100644 index 000000000..c12a89378 --- /dev/null +++ b/src/Wallabag/UserBundle/DependencyInjection/WallabagUserExtension.php @@ -0,0 +1,25 @@ +processConfiguration($configuration, $configs); + + $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); + $loader->load('services.yml'); + } + + public function getAlias() + { + return 'wallabag_user'; + } +} diff --git a/src/Wallabag/UserBundle/Mailer/AuthCodeMailer.php b/src/Wallabag/UserBundle/Mailer/AuthCodeMailer.php new file mode 100644 index 000000000..f1960070d --- /dev/null +++ b/src/Wallabag/UserBundle/Mailer/AuthCodeMailer.php @@ -0,0 +1,93 @@ +mailer = $mailer; + $this->translator = $translator; + $this->senderEmail = $senderEmail; + $this->senderName = $senderName; + $this->supportUrl = $supportUrl; + } + + /** + * Send the auth code to the user via email. + * + * @param TwoFactorInterface $user + */ + public function sendAuthCode(TwoFactorInterface $user) + { + $message = new \Swift_Message(); + $message + ->setTo($user->getEmail()) + ->setFrom($this->senderEmail, $this->senderName) + ->setSubject($this->translator->trans('auth_code.mailer.subject', array(), 'wallabag_user')) + ->setBody($this->translator->trans( + 'auth_code.mailer.body', + [ + '%user%' => $user->getName(), + '%code%' => $user->getEmailAuthCode(), + '%support%' => $this->supportUrl, + ], + 'wallabag_user' + )) + ; + + $this->mailer->send($message); + } +} diff --git a/src/Wallabag/UserBundle/Resources/config/services.yml b/src/Wallabag/UserBundle/Resources/config/services.yml index e69de29bb..9109b6a37 100644 --- a/src/Wallabag/UserBundle/Resources/config/services.yml +++ b/src/Wallabag/UserBundle/Resources/config/services.yml @@ -0,0 +1,9 @@ +services: + wallabag_user.auth_code_mailer: + class: Wallabag\UserBundle\Mailer\AuthCodeMailer + arguments: + - "@mailer" + - "@translator" + - "%scheb_two_factor.email.sender_email%" + - "%scheb_two_factor.email.sender_name%" + - "%wallabag_support_url%" diff --git a/src/Wallabag/UserBundle/Resources/translations/wallabag_user.en.yml b/src/Wallabag/UserBundle/Resources/translations/wallabag_user.en.yml new file mode 100644 index 000000000..f806d1d6f --- /dev/null +++ b/src/Wallabag/UserBundle/Resources/translations/wallabag_user.en.yml @@ -0,0 +1,10 @@ +# Two factor mail +auth_code.mailer.subject: 'Wallabag authentication Code' +auth_code.mailer.body: | + Hi %user%, + + 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. + Here is the code: %code% + + Please don't hesitate to contact us if you have any problems: %support% + The wallabag team diff --git a/src/Wallabag/UserBundle/Resources/translations/wallabag_user.fr.yml b/src/Wallabag/UserBundle/Resources/translations/wallabag_user.fr.yml new file mode 100644 index 000000000..386b2d9eb --- /dev/null +++ b/src/Wallabag/UserBundle/Resources/translations/wallabag_user.fr.yml @@ -0,0 +1,10 @@ +# Two factor mail +auth_code.mailer.subject: "Code d'authentification wallabag" +auth_code.mailer.body: | + Bonjour %user%, + + 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. + Voici le code à renseigner: %code% + + Si vous avez un problème de connexion, n'hésitez pas à contacter le support: %support% + L'équipe wallabag diff --git a/src/Wallabag/UserBundle/Tests/Mailer/AuthCodeMailerTest.php b/src/Wallabag/UserBundle/Tests/Mailer/AuthCodeMailerTest.php new file mode 100644 index 000000000..9122576a3 --- /dev/null +++ b/src/Wallabag/UserBundle/Tests/Mailer/AuthCodeMailerTest.php @@ -0,0 +1,78 @@ +messages); + } + + public function getMessages() + { + return $this->messages; + } +} + +class AuthCodeMailerTest extends \PHPUnit_Framework_TestCase +{ + protected $mailer; + protected $spool; + protected $dataCollector; + + protected function setUp() + { + $this->spool = new CountableMemorySpool(); + $transport = new \Swift_Transport_SpoolTransport( + new \Swift_Events_SimpleEventDispatcher(), + $this->spool + ); + $this->mailer = new \Swift_Mailer($transport); + + $translator = new Translator('en'); + $translator->addLoader('array', new ArrayLoader()); + $translator->addResource('array', array( + 'auth_code.mailer.subject' => 'auth_code subject', + 'auth_code.mailer.body' => 'Hi %user%, here is the code: %code% and the support: %support%', + ), 'en', 'wallabag_user'); + + $this->dataCollector = new DataCollectorTranslator($translator); + } + + public function testSendEmail() + { + $user = new User(); + $user->setTwoFactorAuthentication(true); + $user->setEmailAuthCode(666666); + $user->setEmail('test@wallabag.io'); + $user->setName('Bob'); + + $authCodeMailer = new AuthCodeMailer( + $this->mailer, + $this->dataCollector, + 'nobody@test.io', + 'wallabag test', + 'http://0.0.0.0' + ); + + $authCodeMailer->sendAuthCode($user); + + $this->assertCount(1, $this->spool); + + $msg = $this->spool->getMessages()[0]; + $this->assertArrayHasKey('test@wallabag.io', $msg->getTo()); + $this->assertEquals(array('nobody@test.io' => 'wallabag test'), $msg->getFrom()); + $this->assertEquals('auth_code subject', $msg->getSubject()); + $this->assertContains('Hi Bob, here is the code: 666666 and the support: http://0.0.0.0', $msg->toString()); + } +}