aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/UserBundle/Entity
diff options
context:
space:
mode:
authorNicolas LÅ“uillet <nicolas.loeuillet@smile.fr>2015-10-13 22:43:15 +0200
committerNicolas LÅ“uillet <nicolas.loeuillet@smile.fr>2015-10-13 22:43:15 +0200
commit2db616b586f473238706e554e809086935e0f33a (patch)
tree769c1a8f7c7541a11c2d71fa97a9ff6871d3d210 /src/Wallabag/UserBundle/Entity
parentcf0ea8f113548191cdeb8d3727dd6d2ad25d19ed (diff)
downloadwallabag-2db616b586f473238706e554e809086935e0f33a.tar.gz
wallabag-2db616b586f473238706e554e809086935e0f33a.tar.zst
wallabag-2db616b586f473238706e554e809086935e0f33a.zip
2factor authentication via email
Diffstat (limited to 'src/Wallabag/UserBundle/Entity')
-rw-r--r--src/Wallabag/UserBundle/Entity/User.php68
1 files changed, 67 insertions, 1 deletions
diff --git a/src/Wallabag/UserBundle/Entity/User.php b/src/Wallabag/UserBundle/Entity/User.php
index 8f02e070..d2efd200 100644
--- a/src/Wallabag/UserBundle/Entity/User.php
+++ b/src/Wallabag/UserBundle/Entity/User.php
@@ -4,6 +4,8 @@ namespace Wallabag\UserBundle\Entity;
4 4
5use Doctrine\Common\Collections\ArrayCollection; 5use Doctrine\Common\Collections\ArrayCollection;
6use Doctrine\ORM\Mapping as ORM; 6use Doctrine\ORM\Mapping as ORM;
7use Scheb\TwoFactorBundle\Model\Email\TwoFactorInterface;
8use Scheb\TwoFactorBundle\Model\TrustedComputerInterface;
7use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; 9use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
8use Symfony\Component\Security\Core\User\UserInterface; 10use Symfony\Component\Security\Core\User\UserInterface;
9use JMS\Serializer\Annotation\ExclusionPolicy; 11use JMS\Serializer\Annotation\ExclusionPolicy;
@@ -24,7 +26,7 @@ use Wallabag\CoreBundle\Entity\Tag;
24 * @UniqueEntity("email") 26 * @UniqueEntity("email")
25 * @UniqueEntity("username") 27 * @UniqueEntity("username")
26 */ 28 */
27class User extends BaseUser 29class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterface
28{ 30{
29 /** 31 /**
30 * @var int 32 * @var int
@@ -72,6 +74,22 @@ class User extends BaseUser
72 */ 74 */
73 protected $tags; 75 protected $tags;
74 76
77 /**
78 * @ORM\Column(type="integer", nullable=true)
79 */
80 private $authCode;
81
82 /**
83 * @var bool Enabled yes/no
84 * @ORM\Column(type="boolean")
85 */
86 private $twoFactorAuthentication = false;
87
88 /**
89 * @ORM\Column(type="json_array", nullable=true)
90 */
91 private $trusted;
92
75 public function __construct() 93 public function __construct()
76 { 94 {
77 parent::__construct(); 95 parent::__construct();
@@ -201,4 +219,52 @@ class User extends BaseUser
201 { 219 {
202 return $this->config; 220 return $this->config;
203 } 221 }
222
223 /**
224 * @return bool
225 */
226 public function isTwoFactorAuthentication()
227 {
228 return $this->twoFactorAuthentication;
229 }
230
231 /**
232 * @param bool $twoFactorAuthentication
233 */
234 public function setTwoFactorAuthentication($twoFactorAuthentication)
235 {
236 $this->twoFactorAuthentication = $twoFactorAuthentication;
237 }
238
239 public function isEmailAuthEnabled()
240 {
241 return $this->twoFactorAuthentication;
242 }
243
244 public function getEmailAuthCode()
245 {
246 return $this->authCode;
247 }
248
249 public function setEmailAuthCode($authCode)
250 {
251 $this->authCode = $authCode;
252 }
253
254 public function addTrustedComputer($token, \DateTime $validUntil)
255 {
256 $this->trusted[$token] = $validUntil->format('r');
257 }
258
259 public function isTrustedComputer($token)
260 {
261 if (isset($this->trusted[$token])) {
262 $now = new \DateTime();
263 $validUntil = new \DateTime($this->trusted[$token]);
264
265 return $now < $validUntil;
266 }
267
268 return false;
269 }
204} 270}