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
;
20 * @ORM\Entity(repositoryClass="Wallabag\UserBundle\Repository\UserRepository")
21 * @ORM\Table(name="`user`")
22 * @ORM\HasLifecycleCallbacks()
23 * @ExclusionPolicy("all")
25 * @UniqueEntity("email")
26 * @UniqueEntity("username")
28 class User
extends BaseUser
implements TwoFactorInterface
, TrustedComputerInterface
34 * @ORM\Column(name="id", type="integer")
36 * @ORM\GeneratedValue(strategy="AUTO")
43 * @ORM\Column(name="name", type="text", nullable=true)
50 * @ORM\Column(name="created_at", type="datetime")
57 * @ORM\Column(name="updated_at", type="datetime")
62 * @ORM\OneToMany(targetEntity="Wallabag\CoreBundle\Entity\Entry", mappedBy="user", cascade={"remove"})
67 * @ORM\OneToOne(targetEntity="Wallabag\CoreBundle\Entity\Config", mappedBy="user")
72 * @ORM\Column(type="integer", nullable=true)
77 * @var bool Enabled yes/no
78 * @ORM\Column(type="boolean")
80 private $twoFactorAuthentication = false;
83 * @ORM\Column(type="json_array", nullable=true)
90 * @ORM\Column(name="last_pocket_import", type="datetime", nullable=true)
92 private $lastPocketImport;
94 public function __construct()
96 parent
::__construct();
97 $this->entries
= 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
;
174 public function isEqualTo(UserInterface
$user)
176 return $this->username
=== $user->getUsername();
182 * @param Config $config
186 public function setConfig(Config
$config = null)
188 $this->config
= $config;
198 public function getConfig()
200 return $this->config
;
206 public function isTwoFactorAuthentication()
208 return $this->twoFactorAuthentication
;
212 * @param bool $twoFactorAuthentication
214 public function setTwoFactorAuthentication($twoFactorAuthentication)
216 $this->twoFactorAuthentication
= $twoFactorAuthentication;
219 public function isEmailAuthEnabled()
221 return $this->twoFactorAuthentication
;
224 public function getEmailAuthCode()
226 return $this->authCode
;
229 public function setEmailAuthCode($authCode)
231 $this->authCode
= $authCode;
234 public function addTrustedComputer($token, \DateTime
$validUntil)
236 $this->trusted
[$token] = $validUntil->format('r');
239 public function isTrustedComputer($token)
241 if (isset($this->trusted
[$token])) {
242 $now = new \
DateTime();
243 $validUntil = new \
DateTime($this->trusted
[$token]);
245 return $now < $validUntil;
254 public function getLastPocketImport()
256 return $this->lastPocketImport
;
260 * @param date $lastPocketImport
262 public function setLastPocketImport($lastPocketImport)
264 $this->lastPocketImport
= $lastPocketImport;