3 namespace Wallabag\CoreBundle\Entity
;
5 use Doctrine\Common\Collections\ArrayCollection
;
6 use Doctrine\ORM\Mapping
as ORM
;
7 use Symfony\Component\Security\Core\User\UserInterface
;
8 use Symfony\Component\Security\Core\User\AdvancedUserInterface
;
9 use Symfony\Component\Validator\Constraints
as Assert
;
10 use JMS\Serializer\Annotation\ExclusionPolicy
;
11 use JMS\Serializer\Annotation\Expose
;
16 * @ORM\Table(name="user")
18 * @ORM\HasLifecycleCallbacks()
19 * @ExclusionPolicy("all")
21 class User
implements AdvancedUserInterface
, \Serializable
27 * @ORM\Column(name="id", type="integer")
29 * @ORM\GeneratedValue(strategy="AUTO")
36 * @ORM\Column(name="username", type="text")
48 * @ORM\Column(type="string", length=32)
55 * @ORM\Column(name="password", type="text")
62 * @ORM\Column(name="name", type="text", nullable=true)
69 * @ORM\Column(name="email", type="text", nullable=false)
76 * @ORM\Column(name="is_active", type="boolean", nullable=false)
78 private $isActive = true;
83 * @ORM\Column(name="created_at", type="datetime")
90 * @ORM\Column(name="updated_at", type="datetime")
95 * @ORM\OneToMany(targetEntity="Entry", mappedBy="user", cascade={"remove"})
100 * @ORM\OneToOne(targetEntity="Config", mappedBy="user")
104 public function __construct()
106 $this->salt
= md5(uniqid(null, true));
107 $this->entries
= new ArrayCollection();
114 public function timestamps()
116 if (is_null($this->createdAt
)) {
117 $this->createdAt
= new \
DateTime();
120 $this->updatedAt
= new \
DateTime();
128 public function getId()
136 * @param string $username
139 public function setUsername($username)
141 $this->username
= $username;
151 public function getUsername()
153 return $this->username
;
159 public function getSalt()
167 public function getRoles()
169 return array('ROLE_USER');
175 * @param string $password
178 public function setPassword($password)
180 if (!$password && 0 === strlen($password)) {
184 $this->password
= sha1($password.$this->getUsername().$this->getSalt());
194 public function getPassword()
196 return $this->password
;
202 * @param string $name
205 public function setName($name)
217 public function getName()
225 * @param string $email
228 public function setEmail($email)
230 $this->email
= $email;
240 public function getEmail()
248 public function getCreatedAt()
250 return $this->createdAt
;
256 public function getUpdatedAt()
258 return $this->updatedAt
;
262 * @param Entry $entry
266 public function addEntry(Entry
$entry)
268 $this->entries
[] = $entry;
274 * @return ArrayCollection<Entry>
276 public function getEntries()
278 return $this->entries
;
284 public function eraseCredentials()
289 * @see \Serializable::serialize()
291 public function serialize()
293 return serialize(array(
299 * @see \Serializable::unserialize()
301 public function unserialize($serialized)
305 ) = unserialize($serialized);
308 public function isEqualTo(UserInterface
$user)
310 return $this->username
=== $user->getUsername();
313 public function isAccountNonExpired()
318 public function isAccountNonLocked()
323 public function isCredentialsNonExpired()
328 public function isEnabled()
330 return $this->isActive
;
335 * @param \Wallabag\CoreBundle\Entity\Config $config
338 public function setConfig(\Wallabag\CoreBundle\Entity\Config
$config = null)
340 $this->config
= $config;
348 * @return \Wallabag\CoreBundle\Entity\Config
350 public function getConfig()
352 return $this->config
;