1
0
Fork 0
mirror of https://github.com/wallabag/wallabag.git synced 2025-09-15 18:57:05 +00:00

move 2factor activation in parameters

This commit is contained in:
Nicolas Lœuillet 2015-10-15 13:17:21 +02:00
parent 0d6a7929e1
commit 18cf594f8a
5 changed files with 41 additions and 28 deletions

View file

@ -100,6 +100,7 @@
</div>
</fieldset>
{% if twofactor_auth %}
<fieldset class="w500p inline">
<div class="row">
{{ form_label(form.user.twoFactorAuthentication) }}
@ -107,6 +108,7 @@
{{ form_widget(form.user.twoFactorAuthentication) }}
</div>
</fieldset>
{% endif %}
{{ form_rest(form.user) }}
</form>

View file

@ -132,6 +132,7 @@
</div>
</div>
{% if twofactor_auth %}
<div class="row">
<div class="input-field col s12">
{{ form_widget(form.user.twoFactorAuthentication) }}
@ -139,6 +140,7 @@
{{ form_errors(form.user.twoFactorAuthentication) }}
</div>
</div>
{% endif %}
<div class="hidden">{{ form_rest(form.user) }}</div>
<button class="btn waves-effect waves-light" type="submit" name="action">

View file

@ -19,40 +19,46 @@ class SecurityControllerTest extends WallabagCoreTestCase
public function testLoginWith2Factor()
{
$client = $this->getClient();
$client->followRedirects();
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
$user = $em
->getRepository('WallabagUserBundle:User')
->findOneByUsername('admin');
$user->setTwoFactorAuthentication(true);
$em->persist($user);
$em->flush();
if ($client->getContainer()->getParameter('twofactor_auth')) {
$client->followRedirects();
$this->logInAs('admin');
$client->request('GET', '/config');
$this->assertContains('trusted computer', $client->getResponse()->getContent());
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
$user = $em
->getRepository('WallabagUserBundle:User')
->findOneByUsername('admin');
$user->setTwoFactorAuthentication(true);
$em->persist($user);
$em->flush();
// restore user
$user = $em
->getRepository('WallabagUserBundle:User')
->findOneByUsername('admin');
$user->setTwoFactorAuthentication(false);
$em->persist($user);
$em->flush();
$this->logInAs('admin');
$client->request('GET', '/config');
$this->assertContains('trusted computer', $client->getResponse()->getContent());
// restore user
$user = $em
->getRepository('WallabagUserBundle:User')
->findOneByUsername('admin');
$user->setTwoFactorAuthentication(false);
$em->persist($user);
$em->flush();
}
}
public function testTrustedComputer()
{
$client = $this->getClient();
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
$user = $em
->getRepository('WallabagUserBundle:User')
->findOneByUsername('admin');
$date = new \DateTime();
$user->addTrustedComputer('ABCDEF', $date->add(new \DateInterval('P1M')));
$this->assertTrue($user->isTrustedComputer('ABCDEF'));
$this->assertFalse($user->isTrustedComputer('FEDCBA'));
if ($client->getContainer()->getParameter('twofactor_auth')) {
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
$user = $em
->getRepository('WallabagUserBundle:User')
->findOneByUsername('admin');
$date = new \DateTime();
$user->addTrustedComputer('ABCDEF', $date->add(new \DateInterval('P1M')));
$this->assertTrue($user->isTrustedComputer('ABCDEF'));
$this->assertFalse($user->isTrustedComputer('FEDCBA'));
}
}
}