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 Scheb\TwoFactorBundle\Model\Email\TwoFactorInterface
;
9 use Scheb\TwoFactorBundle\Model\TrustedComputerInterface
;
10 use FOS\UserBundle\Model\User
as BaseUser
;
11 use JMS\Serializer\Annotation\ExclusionPolicy
;
12 use JMS\Serializer\Annotation\Expose
;
13 use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity
;
14 use Symfony\Component\Security\Core\User\UserInterface
;
15 use Wallabag\ApiBundle\Entity\Client
;
16 use Wallabag\CoreBundle\Entity\Config
;
17 use Wallabag\CoreBundle\Entity\Entry
;
22 * @ORM\Entity(repositoryClass="Wallabag\UserBundle\Repository\UserRepository")
23 * @ORM\Table(name="`user`")
24 * @ORM\HasLifecycleCallbacks()
25 * @ExclusionPolicy("all")
27 * @UniqueEntity("email")
28 * @UniqueEntity("username")
30 class User
extends BaseUser
implements TwoFactorInterface
, TrustedComputerInterface
36 * @ORM\Column(name="id", type="integer")
38 * @ORM\GeneratedValue(strategy="AUTO")
39 * @Groups({"user_api"})
46 * @ORM\Column(name="name", type="text", nullable=true)
47 * @Groups({"user_api"})
54 * @ORM\Column(name="created_at", type="datetime")
55 * @Groups({"user_api"})
62 * @ORM\Column(name="updated_at", type="datetime")
63 * @Groups({"user_api"})
68 * @ORM\OneToMany(targetEntity="Wallabag\CoreBundle\Entity\Entry", mappedBy="user", cascade={"remove"})
73 * @ORM\OneToOne(targetEntity="Wallabag\CoreBundle\Entity\Config", 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)
94 * @ORM\OneToMany(targetEntity="Wallabag\ApiBundle\Entity\Client", mappedBy="user", cascade={"remove"})
98 public function __construct()
100 parent
::__construct();
101 $this->entries
= new ArrayCollection();
102 $this->roles
= ['ROLE_USER'];
109 public function timestamps()
111 if (is_null($this->createdAt
)) {
112 $this->createdAt
= new \
DateTime();
115 $this->updatedAt
= new \
DateTime();
121 * @param string $name
125 public function setName($name)
137 public function getName()
145 public function getCreatedAt()
147 return $this->createdAt
;
153 public function getUpdatedAt()
155 return $this->updatedAt
;
159 * @param Entry $entry
163 public function addEntry(Entry
$entry)
165 $this->entries
[] = $entry;
171 * @return ArrayCollection<Entry>
173 public function getEntries()
175 return $this->entries
;
178 public function isEqualTo(UserInterface
$user)
180 return $this->username
=== $user->getUsername();
186 * @param Config $config
190 public function setConfig(Config
$config = null)
192 $this->config
= $config;
202 public function getConfig()
204 return $this->config
;
210 public function isTwoFactorAuthentication()
212 return $this->twoFactorAuthentication
;
216 * @param bool $twoFactorAuthentication
218 public function setTwoFactorAuthentication($twoFactorAuthentication)
220 $this->twoFactorAuthentication
= $twoFactorAuthentication;
223 public function isEmailAuthEnabled()
225 return $this->twoFactorAuthentication
;
228 public function getEmailAuthCode()
230 return $this->authCode
;
233 public function setEmailAuthCode($authCode)
235 $this->authCode
= $authCode;
238 public function addTrustedComputer($token, \DateTime
$validUntil)
240 $this->trusted
[$token] = $validUntil->format('r');
243 public function isTrustedComputer($token)
245 if (isset($this->trusted
[$token])) {
246 $now = new \
DateTime();
247 $validUntil = new \
DateTime($this->trusted
[$token]);
249 return $now < $validUntil;
256 * @param Client $client
260 public function addClient(Client
$client)
262 $this->clients
[] = $client;
268 * @return ArrayCollection<Entry>
270 public function getClients()
272 return $this->clients
;