aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle
diff options
context:
space:
mode:
authorJeremy Benoist <j0k3r@users.noreply.github.com>2015-10-15 13:52:52 +0200
committerJeremy Benoist <j0k3r@users.noreply.github.com>2015-10-15 13:52:52 +0200
commit3d3ed955f11006a408c6596eb9151a0afb28e721 (patch)
treeb5bb52afec86a76d39bcca1fb907f4b2d8d5ba82 /src/Wallabag/CoreBundle
parentf6af634aecfa08cc925352610968a20f19b94bd8 (diff)
parente9b395ec4b27bdcc4151292836ecc602f21c57a4 (diff)
downloadwallabag-3d3ed955f11006a408c6596eb9151a0afb28e721.tar.gz
wallabag-3d3ed955f11006a408c6596eb9151a0afb28e721.tar.zst
wallabag-3d3ed955f11006a408c6596eb9151a0afb28e721.zip
Merge pull request #1484 from wallabag/v2-2factor-auth
2factor authentication via email
Diffstat (limited to 'src/Wallabag/CoreBundle')
-rw-r--r--src/Wallabag/CoreBundle/Form/Type/UserInformationType.php1
-rw-r--r--src/Wallabag/CoreBundle/Resources/views/themes/baggy/Config/index.html.twig10
-rw-r--r--src/Wallabag/CoreBundle/Resources/views/themes/material/Config/index.html.twig10
-rw-r--r--src/Wallabag/CoreBundle/Tests/Controller/SecurityControllerTest.php64
4 files changed, 85 insertions, 0 deletions
diff --git a/src/Wallabag/CoreBundle/Form/Type/UserInformationType.php b/src/Wallabag/CoreBundle/Form/Type/UserInformationType.php
index 84f02013..e06c937d 100644
--- a/src/Wallabag/CoreBundle/Form/Type/UserInformationType.php
+++ b/src/Wallabag/CoreBundle/Form/Type/UserInformationType.php
@@ -13,6 +13,7 @@ class UserInformationType extends AbstractType
13 $builder 13 $builder
14 ->add('name', 'text') 14 ->add('name', 'text')
15 ->add('email', 'email') 15 ->add('email', 'email')
16 ->add('twoFactorAuthentication', 'checkbox', array('required' => false))
16 ->add('save', 'submit') 17 ->add('save', 'submit')
17 ->remove('username') 18 ->remove('username')
18 ->remove('plainPassword') 19 ->remove('plainPassword')
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 64305b16..abe5dc9e 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
@@ -100,6 +100,16 @@
100 </div> 100 </div>
101 </fieldset> 101 </fieldset>
102 102
103 {% if twofactor_auth %}
104 <fieldset class="w500p inline">
105 <div class="row">
106 {{ form_label(form.user.twoFactorAuthentication) }}
107 {{ form_errors(form.user.twoFactorAuthentication) }}
108 {{ form_widget(form.user.twoFactorAuthentication) }}
109 </div>
110 </fieldset>
111 {% endif %}
112
103 {{ form_rest(form.user) }} 113 {{ form_rest(form.user) }}
104 </form> 114 </form>
105 115
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 0d8e9f24..ab24d4ef 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
@@ -132,6 +132,16 @@
132 </div> 132 </div>
133 </div> 133 </div>
134 134
135 {% if twofactor_auth %}
136 <div class="row">
137 <div class="input-field col s12">
138 {{ form_widget(form.user.twoFactorAuthentication) }}
139 {{ form_label(form.user.twoFactorAuthentication) }}
140 {{ form_errors(form.user.twoFactorAuthentication) }}
141 </div>
142 </div>
143 {% endif %}
144
135 <div class="hidden">{{ form_rest(form.user) }}</div> 145 <div class="hidden">{{ form_rest(form.user) }}</div>
136 <button class="btn waves-effect waves-light" type="submit" name="action"> 146 <button class="btn waves-effect waves-light" type="submit" name="action">
137 {% trans %}Save{% endtrans %} 147 {% trans %}Save{% endtrans %}
diff --git a/src/Wallabag/CoreBundle/Tests/Controller/SecurityControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/SecurityControllerTest.php
new file mode 100644
index 00000000..b9f5d835
--- /dev/null
+++ b/src/Wallabag/CoreBundle/Tests/Controller/SecurityControllerTest.php
@@ -0,0 +1,64 @@
1<?php
2
3namespace Wallabag\CoreBundle\Tests\Controller;
4
5use Wallabag\CoreBundle\Tests\WallabagCoreTestCase;
6
7class SecurityControllerTest extends WallabagCoreTestCase
8{
9 public function testLoginWithout2Factor()
10 {
11 $this->logInAs('admin');
12 $client = $this->getClient();
13 $client->followRedirects();
14
15 $client->request('GET', '/config');
16 $this->assertContains('RSS', $client->getResponse()->getContent());
17 }
18
19 public function testLoginWith2Factor()
20 {
21 $client = $this->getClient();
22
23 if ($client->getContainer()->getParameter('twofactor_auth')) {
24 $client->followRedirects();
25
26 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
27 $user = $em
28 ->getRepository('WallabagUserBundle:User')
29 ->findOneByUsername('admin');
30 $user->setTwoFactorAuthentication(true);
31 $em->persist($user);
32 $em->flush();
33
34 $this->logInAs('admin');
35 $client->request('GET', '/config');
36 $this->assertContains('trusted computer', $client->getResponse()->getContent());
37
38 // restore user
39 $user = $em
40 ->getRepository('WallabagUserBundle:User')
41 ->findOneByUsername('admin');
42 $user->setTwoFactorAuthentication(false);
43 $em->persist($user);
44 $em->flush();
45 }
46 }
47
48 public function testTrustedComputer()
49 {
50 $client = $this->getClient();
51
52 if ($client->getContainer()->getParameter('twofactor_auth')) {
53 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
54 $user = $em
55 ->getRepository('WallabagUserBundle:User')
56 ->findOneByUsername('admin');
57
58 $date = new \DateTime();
59 $user->addTrustedComputer('ABCDEF', $date->add(new \DateInterval('P1M')));
60 $this->assertTrue($user->isTrustedComputer('ABCDEF'));
61 $this->assertFalse($user->isTrustedComputer('FEDCBA'));
62 }
63 }
64}