diff options
author | Jeremy Benoist <jeremy.benoist@gmail.com> | 2018-12-03 06:51:06 +0100 |
---|---|---|
committer | Jeremy Benoist <jeremy.benoist@gmail.com> | 2019-01-23 13:28:03 +0100 |
commit | dfd0a7bc5feb4fd7b77d7e2f3a25c5c3febc1eba (patch) | |
tree | 112b4403052b0420804dc8a7bcba199f534d902e /src/Wallabag/UserBundle | |
parent | 6e4fc956abc909232044e7af0fa37cbb1b510f18 (diff) | |
download | wallabag-dfd0a7bc5feb4fd7b77d7e2f3a25c5c3febc1eba.tar.gz wallabag-dfd0a7bc5feb4fd7b77d7e2f3a25c5c3febc1eba.tar.zst wallabag-dfd0a7bc5feb4fd7b77d7e2f3a25c5c3febc1eba.zip |
Add backup codes
Diffstat (limited to 'src/Wallabag/UserBundle')
-rw-r--r-- | src/Wallabag/UserBundle/Entity/User.php | 38 |
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; | |||
8 | use JMS\Serializer\Annotation\Accessor; | 8 | use JMS\Serializer\Annotation\Accessor; |
9 | use JMS\Serializer\Annotation\Groups; | 9 | use JMS\Serializer\Annotation\Groups; |
10 | use JMS\Serializer\Annotation\XmlRoot; | 10 | use JMS\Serializer\Annotation\XmlRoot; |
11 | use Scheb\TwoFactorBundle\Model\BackupCodeInterface; | ||
11 | use Scheb\TwoFactorBundle\Model\Email\TwoFactorInterface as EmailTwoFactorInterface; | 12 | use Scheb\TwoFactorBundle\Model\Email\TwoFactorInterface as EmailTwoFactorInterface; |
12 | use Scheb\TwoFactorBundle\Model\Google\TwoFactorInterface as GoogleTwoFactorInterface; | 13 | use Scheb\TwoFactorBundle\Model\Google\TwoFactorInterface as GoogleTwoFactorInterface; |
13 | use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; | 14 | use 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 | */ |
31 | class User extends BaseUser implements EmailTwoFactorInterface, GoogleTwoFactorInterface | 32 | class 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 | * |