aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/UserBundle/Entity
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2018-12-03 06:51:06 +0100
committerJeremy Benoist <jeremy.benoist@gmail.com>2019-01-23 13:28:03 +0100
commitdfd0a7bc5feb4fd7b77d7e2f3a25c5c3febc1eba (patch)
tree112b4403052b0420804dc8a7bcba199f534d902e /src/Wallabag/UserBundle/Entity
parent6e4fc956abc909232044e7af0fa37cbb1b510f18 (diff)
downloadwallabag-dfd0a7bc5feb4fd7b77d7e2f3a25c5c3febc1eba.tar.gz
wallabag-dfd0a7bc5feb4fd7b77d7e2f3a25c5c3febc1eba.tar.zst
wallabag-dfd0a7bc5feb4fd7b77d7e2f3a25c5c3febc1eba.zip
Add backup codes
Diffstat (limited to 'src/Wallabag/UserBundle/Entity')
-rw-r--r--src/Wallabag/UserBundle/Entity/User.php38
1 files changed, 37 insertions, 1 deletions
diff --git a/src/Wallabag/UserBundle/Entity/User.php b/src/Wallabag/UserBundle/Entity/User.php
index 6e305719..ab34e2bf 100644
--- a/src/Wallabag/UserBundle/Entity/User.php
+++ b/src/Wallabag/UserBundle/Entity/User.php
@@ -8,6 +8,7 @@ use FOS\UserBundle\Model\User as BaseUser;
8use JMS\Serializer\Annotation\Accessor; 8use JMS\Serializer\Annotation\Accessor;
9use JMS\Serializer\Annotation\Groups; 9use JMS\Serializer\Annotation\Groups;
10use JMS\Serializer\Annotation\XmlRoot; 10use JMS\Serializer\Annotation\XmlRoot;
11use Scheb\TwoFactorBundle\Model\BackupCodeInterface;
11use Scheb\TwoFactorBundle\Model\Email\TwoFactorInterface as EmailTwoFactorInterface; 12use Scheb\TwoFactorBundle\Model\Email\TwoFactorInterface as EmailTwoFactorInterface;
12use Scheb\TwoFactorBundle\Model\Google\TwoFactorInterface as GoogleTwoFactorInterface; 13use Scheb\TwoFactorBundle\Model\Google\TwoFactorInterface as GoogleTwoFactorInterface;
13use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; 14use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
@@ -28,7 +29,7 @@ use Wallabag\CoreBundle\Helper\EntityTimestampsTrait;
28 * @UniqueEntity("email") 29 * @UniqueEntity("email")
29 * @UniqueEntity("username") 30 * @UniqueEntity("username")
30 */ 31 */
31class User extends BaseUser implements EmailTwoFactorInterface, GoogleTwoFactorInterface 32class User extends BaseUser implements EmailTwoFactorInterface, GoogleTwoFactorInterface, BackupCodeInterface
32{ 33{
33 use EntityTimestampsTrait; 34 use EntityTimestampsTrait;
34 35
@@ -128,6 +129,11 @@ class User extends BaseUser implements EmailTwoFactorInterface, GoogleTwoFactorI
128 private $googleAuthenticatorSecret; 129 private $googleAuthenticatorSecret;
129 130
130 /** 131 /**
132 * @ORM\Column(type="json_array", nullable=true)
133 */
134 private $backupCodes;
135
136 /**
131 * @var bool 137 * @var bool
132 * 138 *
133 * @ORM\Column(type="boolean") 139 * @ORM\Column(type="boolean")
@@ -318,6 +324,36 @@ class User extends BaseUser implements EmailTwoFactorInterface, GoogleTwoFactorI
318 $this->googleAuthenticatorSecret = $googleAuthenticatorSecret; 324 $this->googleAuthenticatorSecret = $googleAuthenticatorSecret;
319 } 325 }
320 326
327 public function setBackupCodes(array $codes = null)
328 {
329 $this->backupCodes = $codes;
330 }
331
332 public function getBackupCodes()
333 {
334 return $this->backupCodes;
335 }
336
337 /**
338 * {@inheritdoc}
339 */
340 public function isBackupCode(string $code): bool
341 {
342 return \in_array($code, $this->backupCodes, true);
343 }
344
345 /**
346 * {@inheritdoc}
347 */
348 public function invalidateBackupCode(string $code): void
349 {
350 $key = array_search($code, $this->backupCodes, true);
351
352 if (false !== $key) {
353 unset($this->backupCodes[$key]);
354 }
355 }
356
321 /** 357 /**
322 * @param Client $client 358 * @param Client $client
323 * 359 *