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 FOS\UserBundle\Model\User
as BaseUser
;
10 use JMS\Serializer\Annotation\ExclusionPolicy
;
11 use JMS\Serializer\Annotation\Expose
;
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
;
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", cascade={"remove"})
73 * @ORM\Column(type="integer", nullable=true)
78 * @var bool Enabled yes/no
79 * @ORM\Column(type="boolean")
81 private $twoFactorAuthentication = false;
84 * @ORM\Column(type="json_array", nullable=true)
89 * @ORM\OneToMany(targetEntity="Wallabag\ApiBundle\Entity\Client", mappedBy="user", cascade={"remove"})
93 public function __construct()
95 parent
::__construct();
96 $this->entries
= new ArrayCollection();
97 $this->roles
= ['ROLE_USER'];
104 public function timestamps()
106 if (is_null($this->createdAt
)) {
107 $this->createdAt
= new \
DateTime();
110 $this->updatedAt
= new \
DateTime();
116 * @param string $name
120 public function setName($name)
132 public function getName()
140 public function getCreatedAt()
142 return $this->createdAt
;
148 public function getUpdatedAt()
150 return $this->updatedAt
;
154 * @param Entry $entry
158 public function addEntry(Entry
$entry)
160 $this->entries
[] = $entry;
166 * @return ArrayCollection<Entry>
168 public function getEntries()
170 return $this->entries
;
173 public function isEqualTo(UserInterface
$user)
175 return $this->username
=== $user->getUsername();
181 * @param Config $config
185 public function setConfig(Config
$config = null)
187 $this->config
= $config;
197 public function getConfig()
199 return $this->config
;
205 public function isTwoFactorAuthentication()
207 return $this->twoFactorAuthentication
;
211 * @param bool $twoFactorAuthentication
213 public function setTwoFactorAuthentication($twoFactorAuthentication)
215 $this->twoFactorAuthentication
= $twoFactorAuthentication;
218 public function isEmailAuthEnabled()
220 return $this->twoFactorAuthentication
;
223 public function getEmailAuthCode()
225 return $this->authCode
;
228 public function setEmailAuthCode($authCode)
230 $this->authCode
= $authCode;
233 public function addTrustedComputer($token, \DateTime
$validUntil)
235 $this->trusted
[$token] = $validUntil->format('r');
238 public function isTrustedComputer($token)
240 if (isset($this->trusted
[$token])) {
241 $now = new \
DateTime();
242 $validUntil = new \
DateTime($this->trusted
[$token]);
244 return $now < $validUntil;
251 * @param Client $client
255 public function addClient(Client
$client)
257 $this->clients
[] = $client;
263 * @return ArrayCollection<Entry>
265 public function getClients()
267 return $this->clients
;