namespace Wallabag\CoreBundle\Entity;
+use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\User\AdvancedUserInterface;
+use Symfony\Component\Validator\Constraints as Assert;
/**
* User
* @var string
*
* @ORM\Column(name="username", type="text")
+ * @Assert\NotBlank()
+ * @Assert\Length(
+ * min = "3",
+ * max = "255"
+ * )
*/
private $username;
/**
* @var string
*
- * @ORM\Column(name="email", type="text", nullable=true)
+ * @ORM\Column(name="email", type="text", nullable=false)
+ * @Assert\Email()
+ * @Assert\NotBlank()
*/
private $email;
/**
- * @ORM\Column(name="is_active", type="boolean")
+ * @ORM\Column(name="is_active", type="boolean", nullable=false)
*/
- private $isActive;
+ private $isActive = true;
/**
* @var date
*/
private $updatedAt;
+ /**
+ * @ORM\OneToMany(targetEntity="Entry", mappedBy="user", cascade={"remove"})
+ */
+ private $entries;
+
+ /**
+ * @ORM\OneToOne(targetEntity="Config", mappedBy="user")
+ */
+ private $config;
+
public function __construct()
{
- $this->isActive = true;
- $this->salt = md5(uniqid(null, true));
+ $this->salt = md5(uniqid(null, true));
+ $this->entries = new ArrayCollection();
}
/**
*/
public function setPassword($password)
{
- $this->password = $password;
+ if (!$password && 0 === strlen($password)) {
+ return;
+ }
+
+ $this->password = sha1($password.$this->getUsername().$this->getSalt());
return $this;
}
return $this->updatedAt;
}
+ /**
+ * @param Entry $entry
+ *
+ * @return User
+ */
+ public function addEntry(Entry $entry)
+ {
+ $this->entries[] = $entry;
+
+ return $this;
+ }
+
+ /**
+ * @return ArrayCollection<Entry>
+ */
+ public function getEntries()
+ {
+ return $this->entries;
+ }
+
/**
* @inheritDoc
*/
{
return $this->isActive;
}
+ /**
+ * Set config
+ *
+ * @param \Wallabag\CoreBundle\Entity\Config $config
+ * @return User
+ */
+ public function setConfig(\Wallabag\CoreBundle\Entity\Config $config = null)
+ {
+ $this->config = $config;
+
+ return $this;
+ }
+
+ /**
+ * Get config
+ *
+ * @return \Wallabag\CoreBundle\Entity\Config
+ */
+ public function getConfig()
+ {
+ return $this->config;
+ }
}