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
;
13 * @ORM\Table(name="user")
15 * @ORM\HasLifecycleCallbacks()
17 class User
implements AdvancedUserInterface
, \Serializable
22 * @ORM\Column(name="id", type="integer")
24 * @ORM\GeneratedValue(strategy="AUTO")
31 * @ORM\Column(name="username", type="text")
38 * @ORM\Column(type="string", length=32)
45 * @ORM\Column(name="password", type="text")
52 * @ORM\Column(name="name", type="text", nullable=true)
59 * @ORM\Column(name="email", type="text", nullable=true)
64 * @ORM\Column(name="is_active", type="boolean")
71 * @ORM\Column(name="created_at", type="datetime")
78 * @ORM\Column(name="updated_at", type="datetime")
83 * @ORM\OneToMany(targetEntity="Entry", mappedBy="user", cascade={"remove"})
87 public function __construct()
89 $this->isActive
= true;
90 $this->salt
= md5(uniqid(null, true));
91 $this->entries
= new ArrayCollection();
98 public function timestamps()
100 if (is_null($this->createdAt
)) {
101 $this->createdAt
= new \
DateTime();
104 $this->updatedAt
= new \
DateTime();
112 public function getId()
120 * @param string $username
123 public function setUsername($username)
125 $this->username
= $username;
135 public function getUsername()
137 return $this->username
;
143 public function getSalt()
151 public function getRoles()
153 return array('ROLE_USER');
159 * @param string $password
162 public function setPassword($password)
164 if (!$password && 0 === strlen($password)) {
168 $this->password
= sha1($password.$this->getUsername().$this->getSalt());
178 public function getPassword()
180 return $this->password
;
186 * @param string $name
189 public function setName($name)
201 public function getName()
209 * @param string $email
212 public function setEmail($email)
214 $this->email
= $email;
224 public function getEmail()
232 public function getCreatedAt()
234 return $this->createdAt
;
240 public function getUpdatedAt()
242 return $this->updatedAt
;
246 * @param Entry $entry
250 public function addEntry(Entry
$entry)
252 $this->entries
[] = $entry;
258 * @return ArrayCollection<Entry>
260 public function getEntries()
262 return $this->entries
;
268 public function eraseCredentials()
273 * @see \Serializable::serialize()
275 public function serialize()
277 return serialize(array(
283 * @see \Serializable::unserialize()
285 public function unserialize($serialized)
289 ) = unserialize($serialized);
292 public function isEqualTo(UserInterface
$user)
294 return $this->username
=== $user->getUsername();
297 public function isAccountNonExpired()
302 public function isAccountNonLocked()
307 public function isCredentialsNonExpired()
312 public function isEnabled()
314 return $this->isActive
;