3 namespace Wallabag\UserBundle\Entity
;
5 use Doctrine\Common\Collections\ArrayCollection
;
6 use Doctrine\ORM\Mapping
as ORM
;
7 use JMS\Serializer\Annotation\Groups
;
8 use JMS\Serializer\Annotation\XmlRoot
;
9 use Scheb\TwoFactorBundle\Model\Email\TwoFactorInterface
;
10 use Scheb\TwoFactorBundle\Model\TrustedComputerInterface
;
11 use FOS\UserBundle\Model\User
as BaseUser
;
12 use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity
;
13 use Symfony\Component\Security\Core\User\UserInterface
;
14 use Wallabag\ApiBundle\Entity\Client
;
15 use Wallabag\CoreBundle\Entity\Config
;
16 use Wallabag\CoreBundle\Entity\Entry
;
22 * @ORM\Entity(repositoryClass="Wallabag\UserBundle\Repository\UserRepository")
23 * @ORM\Table(name="`user`")
24 * @ORM\HasLifecycleCallbacks()
26 * @UniqueEntity("email")
27 * @UniqueEntity("username")
29 class User
extends BaseUser
implements TwoFactorInterface
, TrustedComputerInterface
31 /** @Serializer\XmlAttribute */
35 * @ORM\Column(name="id", type="integer")
37 * @ORM\GeneratedValue(strategy="AUTO")
39 * @Groups({"user_api"})
46 * @ORM\Column(name="name", type="text", nullable=true)
48 * @Groups({"user_api"})
55 * @Groups({"user_api"})
62 * @Groups({"user_api"})
69 * @ORM\Column(name="created_at", type="datetime")
71 * @Groups({"user_api"})
78 * @ORM\Column(name="updated_at", type="datetime")
80 * @Groups({"user_api"})
85 * @ORM\OneToMany(targetEntity="Wallabag\CoreBundle\Entity\Entry", mappedBy="user", cascade={"remove"})
90 * @ORM\OneToOne(targetEntity="Wallabag\CoreBundle\Entity\Config", mappedBy="user", cascade={"remove"})
95 * @ORM\Column(type="integer", nullable=true)
100 * @var bool Enabled yes/no
101 * @ORM\Column(type="boolean")
103 private $twoFactorAuthentication = false;
106 * @ORM\Column(type="json_array", nullable=true)
111 * @ORM\OneToMany(targetEntity="Wallabag\ApiBundle\Entity\Client", mappedBy="user", cascade={"remove"})
115 public function __construct()
117 parent
::__construct();
118 $this->entries
= new ArrayCollection();
119 $this->roles
= ['ROLE_USER'];
126 public function timestamps()
128 if (is_null($this->createdAt
)) {
129 $this->createdAt
= new \
DateTime();
132 $this->updatedAt
= new \
DateTime();
138 * @param string $name
142 public function setName($name)
154 public function getName()
162 public function getCreatedAt()
164 return $this->createdAt
;
170 public function getUpdatedAt()
172 return $this->updatedAt
;
176 * @param Entry $entry
180 public function addEntry(Entry
$entry)
182 $this->entries
[] = $entry;
188 * @return ArrayCollection<Entry>
190 public function getEntries()
192 return $this->entries
;
195 public function isEqualTo(UserInterface
$user)
197 return $this->username
=== $user->getUsername();
203 * @param Config $config
207 public function setConfig(Config
$config = null)
209 $this->config
= $config;
219 public function getConfig()
221 return $this->config
;
227 public function isTwoFactorAuthentication()
229 return $this->twoFactorAuthentication
;
233 * @param bool $twoFactorAuthentication
235 public function setTwoFactorAuthentication($twoFactorAuthentication)
237 $this->twoFactorAuthentication
= $twoFactorAuthentication;
240 public function isEmailAuthEnabled()
242 return $this->twoFactorAuthentication
;
245 public function getEmailAuthCode()
247 return $this->authCode
;
250 public function setEmailAuthCode($authCode)
252 $this->authCode
= $authCode;
255 public function addTrustedComputer($token, \DateTime
$validUntil)
257 $this->trusted
[$token] = $validUntil->format('r');
260 public function isTrustedComputer($token)
262 if (isset($this->trusted
[$token])) {
263 $now = new \
DateTime();
264 $validUntil = new \
DateTime($this->trusted
[$token]);
266 return $now < $validUntil;
273 * @param Client $client
277 public function addClient(Client
$client)
279 $this->clients
[] = $client;
285 * @return ArrayCollection<Entry>
287 public function getClients()
289 return $this->clients
;