3 namespace Wallabag\UserBundle\Entity
;
5 use Doctrine\Common\Collections\ArrayCollection
;
6 use Doctrine\ORM\Mapping
as ORM
;
7 use Scheb\TwoFactorBundle\Model\Email\TwoFactorInterface
;
8 use Scheb\TwoFactorBundle\Model\TrustedComputerInterface
;
9 use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity
;
10 use Symfony\Component\Security\Core\User\UserInterface
;
11 use JMS\Serializer\Annotation\ExclusionPolicy
;
12 use JMS\Serializer\Annotation\Expose
;
13 use FOS\UserBundle\Model\User
as BaseUser
;
14 use Wallabag\CoreBundle\Entity\Config
;
15 use Wallabag\CoreBundle\Entity\Entry
;
16 use Wallabag\CoreBundle\Entity\Tag
;
21 * @ORM\Entity(repositoryClass="Wallabag\UserBundle\Repository\UserRepository")
22 * @ORM\Table(name="`user`")
23 * @ORM\HasLifecycleCallbacks()
24 * @ExclusionPolicy("all")
26 * @UniqueEntity("email")
27 * @UniqueEntity("username")
29 class User
extends BaseUser
implements TwoFactorInterface
, TrustedComputerInterface
35 * @ORM\Column(name="id", type="integer")
37 * @ORM\GeneratedValue(strategy="AUTO")
44 * @ORM\Column(name="name", type="text", nullable=true)
51 * @ORM\Column(name="created_at", type="datetime")
58 * @ORM\Column(name="updated_at", type="datetime")
63 * @ORM\OneToMany(targetEntity="Wallabag\CoreBundle\Entity\Entry", mappedBy="user", cascade={"remove"})
68 * @ORM\OneToOne(targetEntity="Wallabag\CoreBundle\Entity\Config", mappedBy="user")
73 * @ORM\OneToMany(targetEntity="Wallabag\CoreBundle\Entity\Tag", mappedBy="user", cascade={"remove"})
78 * @ORM\Column(type="integer", nullable=true)
83 * @var bool Enabled yes/no
84 * @ORM\Column(type="boolean")
86 private $twoFactorAuthentication = false;
89 * @ORM\Column(type="json_array", nullable=true)
93 public function __construct()
95 parent
::__construct();
96 $this->entries
= new ArrayCollection();
97 $this->tags
= new ArrayCollection();
98 $this->roles
= array('ROLE_USER');
105 public function timestamps()
107 if (is_null($this->createdAt
)) {
108 $this->createdAt
= new \
DateTime();
111 $this->updatedAt
= new \
DateTime();
117 * @param string $name
121 public function setName($name)
133 public function getName()
141 public function getCreatedAt()
143 return $this->createdAt
;
149 public function getUpdatedAt()
151 return $this->updatedAt
;
155 * @param Entry $entry
159 public function addEntry(Entry
$entry)
161 $this->entries
[] = $entry;
167 * @return ArrayCollection<Entry>
169 public function getEntries()
171 return $this->entries
;
175 * @param Entry $entry
179 public function addTag(Tag
$tag)
181 $this->tags
[] = $tag;
187 * @return ArrayCollection<Tag>
189 public function getTags()
194 public function isEqualTo(UserInterface
$user)
196 return $this->username
=== $user->getUsername();
202 * @param Config $config
206 public function setConfig(Config
$config = null)
208 $this->config
= $config;
218 public function getConfig()
220 return $this->config
;
226 public function isTwoFactorAuthentication()
228 return $this->twoFactorAuthentication
;
232 * @param bool $twoFactorAuthentication
234 public function setTwoFactorAuthentication($twoFactorAuthentication)
236 $this->twoFactorAuthentication
= $twoFactorAuthentication;
239 public function isEmailAuthEnabled()
241 return $this->twoFactorAuthentication
;
244 public function getEmailAuthCode()
246 return $this->authCode
;
249 public function setEmailAuthCode($authCode)
251 $this->authCode
= $authCode;
254 public function addTrustedComputer($token, \DateTime
$validUntil)
256 $this->trusted
[$token] = $validUntil->format('r');
259 public function isTrustedComputer($token)
261 if (isset($this->trusted
[$token])) {
262 $now = new \
DateTime();
263 $validUntil = new \
DateTime($this->trusted
[$token]);
265 return $now < $validUntil;