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\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)
87 public function __construct()
89 parent
::__construct();
90 $this->entries
= new ArrayCollection();
91 $this->roles
= array('ROLE_USER');
98 public function timestamps()
100 if (is_null($this->createdAt
)) {
101 $this->createdAt
= new \
DateTime();
104 $this->updatedAt
= new \
DateTime();
110 * @param string $name
114 public function setName($name)
126 public function getName()
134 public function getCreatedAt()
136 return $this->createdAt
;
142 public function getUpdatedAt()
144 return $this->updatedAt
;
148 * @param Entry $entry
152 public function addEntry(Entry
$entry)
154 $this->entries
[] = $entry;
160 * @return ArrayCollection<Entry>
162 public function getEntries()
164 return $this->entries
;
167 public function isEqualTo(UserInterface
$user)
169 return $this->username
=== $user->getUsername();
175 * @param Config $config
179 public function setConfig(Config
$config = null)
181 $this->config
= $config;
191 public function getConfig()
193 return $this->config
;
199 public function isTwoFactorAuthentication()
201 return $this->twoFactorAuthentication
;
205 * @param bool $twoFactorAuthentication
207 public function setTwoFactorAuthentication($twoFactorAuthentication)
209 $this->twoFactorAuthentication
= $twoFactorAuthentication;
212 public function isEmailAuthEnabled()
214 return $this->twoFactorAuthentication
;
217 public function getEmailAuthCode()
219 return $this->authCode
;
222 public function setEmailAuthCode($authCode)
224 $this->authCode
= $authCode;
227 public function addTrustedComputer($token, \DateTime
$validUntil)
229 $this->trusted
[$token] = $validUntil->format('r');
232 public function isTrustedComputer($token)
234 if (isset($this->trusted
[$token])) {
235 $now = new \
DateTime();
236 $validUntil = new \
DateTime($this->trusted
[$token]);
238 return $now < $validUntil;