aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/UserBundle/Entity/User.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Wallabag/UserBundle/Entity/User.php')
-rw-r--r--src/Wallabag/UserBundle/Entity/User.php94
1 files changed, 67 insertions, 27 deletions
diff --git a/src/Wallabag/UserBundle/Entity/User.php b/src/Wallabag/UserBundle/Entity/User.php
index 48446e3c..6e305719 100644
--- a/src/Wallabag/UserBundle/Entity/User.php
+++ b/src/Wallabag/UserBundle/Entity/User.php
@@ -8,8 +8,8 @@ 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\Email\TwoFactorInterface; 11use Scheb\TwoFactorBundle\Model\Email\TwoFactorInterface as EmailTwoFactorInterface;
12use Scheb\TwoFactorBundle\Model\TrustedComputerInterface; 12use Scheb\TwoFactorBundle\Model\Google\TwoFactorInterface as GoogleTwoFactorInterface;
13use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; 13use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
14use Symfony\Component\Security\Core\User\UserInterface; 14use Symfony\Component\Security\Core\User\UserInterface;
15use Wallabag\ApiBundle\Entity\Client; 15use Wallabag\ApiBundle\Entity\Client;
@@ -28,7 +28,7 @@ use Wallabag\CoreBundle\Helper\EntityTimestampsTrait;
28 * @UniqueEntity("email") 28 * @UniqueEntity("email")
29 * @UniqueEntity("username") 29 * @UniqueEntity("username")
30 */ 30 */
31class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterface 31class User extends BaseUser implements EmailTwoFactorInterface, GoogleTwoFactorInterface
32{ 32{
33 use EntityTimestampsTrait; 33 use EntityTimestampsTrait;
34 34
@@ -123,16 +123,16 @@ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterf
123 private $authCode; 123 private $authCode;
124 124
125 /** 125 /**
126 * @var bool 126 * @ORM\Column(name="googleAuthenticatorSecret", type="string", nullable=true)
127 *
128 * @ORM\Column(type="boolean")
129 */ 127 */
130 private $twoFactorAuthentication = false; 128 private $googleAuthenticatorSecret;
131 129
132 /** 130 /**
133 * @ORM\Column(type="json_array", nullable=true) 131 * @var bool
132 *
133 * @ORM\Column(type="boolean")
134 */ 134 */
135 private $trusted; 135 private $emailTwoFactor = false;
136 136
137 public function __construct() 137 public function __construct()
138 { 138 {
@@ -233,49 +233,89 @@ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterf
233 /** 233 /**
234 * @return bool 234 * @return bool
235 */ 235 */
236 public function isTwoFactorAuthentication() 236 public function isEmailTwoFactor()
237 {
238 return $this->emailTwoFactor;
239 }
240
241 /**
242 * @param bool $emailTwoFactor
243 */
244 public function setEmailTwoFactor($emailTwoFactor)
237 { 245 {
238 return $this->twoFactorAuthentication; 246 $this->emailTwoFactor = $emailTwoFactor;
239 } 247 }
240 248
241 /** 249 /**
242 * @param bool $twoFactorAuthentication 250 * Used in the user config form to be "like" the email option.
243 */ 251 */
244 public function setTwoFactorAuthentication($twoFactorAuthentication) 252 public function isGoogleTwoFactor()
245 { 253 {
246 $this->twoFactorAuthentication = $twoFactorAuthentication; 254 return $this->isGoogleAuthenticatorEnabled();
247 } 255 }
248 256
249 public function isEmailAuthEnabled() 257 /**
258 * {@inheritdoc}
259 */
260 public function isEmailAuthEnabled(): bool
250 { 261 {
251 return $this->twoFactorAuthentication; 262 return $this->emailTwoFactor;
252 } 263 }
253 264
254 public function getEmailAuthCode() 265 /**
266 * {@inheritdoc}
267 */
268 public function getEmailAuthCode(): string
255 { 269 {
256 return $this->authCode; 270 return $this->authCode;
257 } 271 }
258 272
259 public function setEmailAuthCode($authCode) 273 /**
274 * {@inheritdoc}
275 */
276 public function setEmailAuthCode(string $authCode): void
260 { 277 {
261 $this->authCode = $authCode; 278 $this->authCode = $authCode;
262 } 279 }
263 280
264 public function addTrustedComputer($token, \DateTime $validUntil) 281 /**
282 * {@inheritdoc}
283 */
284 public function getEmailAuthRecipient(): string
265 { 285 {
266 $this->trusted[$token] = $validUntil->format('r'); 286 return $this->email;
267 } 287 }
268 288
269 public function isTrustedComputer($token) 289 /**
290 * {@inheritdoc}
291 */
292 public function isGoogleAuthenticatorEnabled(): bool
270 { 293 {
271 if (isset($this->trusted[$token])) { 294 return $this->googleAuthenticatorSecret ? true : false;
272 $now = new \DateTime(); 295 }
273 $validUntil = new \DateTime($this->trusted[$token]);
274 296
275 return $now < $validUntil; 297 /**
276 } 298 * {@inheritdoc}
299 */
300 public function getGoogleAuthenticatorUsername(): string
301 {
302 return $this->username;
303 }
277 304
278 return false; 305 /**
306 * {@inheritdoc}
307 */
308 public function getGoogleAuthenticatorSecret(): string
309 {
310 return $this->googleAuthenticatorSecret;
311 }
312
313 /**
314 * {@inheritdoc}
315 */
316 public function setGoogleAuthenticatorSecret(?string $googleAuthenticatorSecret): void
317 {
318 $this->googleAuthenticatorSecret = $googleAuthenticatorSecret;
279 } 319 }
280 320
281 /** 321 /**