X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FCoreBundle%2FEntity%2FUser.php;h=00eb808a626839c1e12d5c879f1d19d6a197878b;hb=a2cdaa8cdd12086d0e6eb91954862bf7f3177d12;hp=cfbd57f8835049f19b52d5497906b92e0e37a28b;hpb=5f09650eef7bea52b7c54c074c0f873f96e53c86;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/CoreBundle/Entity/User.php b/src/Wallabag/CoreBundle/Entity/User.php index cfbd57f8..00eb808a 100644 --- a/src/Wallabag/CoreBundle/Entity/User.php +++ b/src/Wallabag/CoreBundle/Entity/User.php @@ -4,21 +4,30 @@ namespace Wallabag\CoreBundle\Entity; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\Mapping as ORM; +use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; use Symfony\Component\Security\Core\User\UserInterface; use Symfony\Component\Security\Core\User\AdvancedUserInterface; +use Symfony\Component\Validator\Constraints as Assert; +use JMS\Serializer\Annotation\ExclusionPolicy; +use JMS\Serializer\Annotation\Expose; /** - * User + * User. * - * @ORM\Table(name="user") - * @ORM\Entity + * @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\UserRepository") + * @ORM\Table * @ORM\HasLifecycleCallbacks() + * @ExclusionPolicy("all") + * + * @UniqueEntity("email") + * @UniqueEntity("username") */ class User implements AdvancedUserInterface, \Serializable { /** - * @var integer + * @var int * + * @Expose * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") @@ -29,6 +38,11 @@ class User implements AdvancedUserInterface, \Serializable * @var string * * @ORM\Column(name="username", type="text") + * @Assert\NotBlank() + * @Assert\Length( + * min = "3", + * max = "255" + * ) */ private $username; @@ -56,14 +70,26 @@ class User implements AdvancedUserInterface, \Serializable /** * @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 = true; + + /** + * @ORM\Column(name="confirmation_token", type="string", nullable=true) */ - private $isActive; + private $confirmationToken; + + /** + * @ORM\Column(name="password_requested_at", type="datetime", nullable=true) + */ + private $passwordRequestedAt; /** * @var date @@ -84,11 +110,22 @@ class User implements AdvancedUserInterface, \Serializable */ private $entries; + /** + * @ORM\OneToOne(targetEntity="Config", mappedBy="user") + */ + private $config; + + /** + * @ORM\OneToMany(targetEntity="Tag", mappedBy="user", cascade={"remove"}) + */ + private $tags; + public function __construct() { $this->isActive = true; $this->salt = md5(uniqid(null, true)); $this->entries = new ArrayCollection(); + $this->tags = new ArrayCollection(); } /** @@ -105,9 +142,9 @@ class User implements AdvancedUserInterface, \Serializable } /** - * Get id + * Get id. * - * @return integer + * @return int */ public function getId() { @@ -115,9 +152,10 @@ class User implements AdvancedUserInterface, \Serializable } /** - * Set username + * Set username. + * + * @param string $username * - * @param string $username * @return User */ public function setUsername($username) @@ -128,7 +166,7 @@ class User implements AdvancedUserInterface, \Serializable } /** - * Get username + * Get username. * * @return string */ @@ -154,20 +192,25 @@ class User implements AdvancedUserInterface, \Serializable } /** - * Set password + * Set password. + * + * @param string $password * - * @param string $password * @return User */ public function setPassword($password) { - $this->password = $password; + if (!$password && 0 === strlen($password)) { + return; + } + + $this->password = sha1($password.$this->getUsername().$this->getSalt()); return $this; } /** - * Get password + * Get password. * * @return string */ @@ -177,9 +220,10 @@ class User implements AdvancedUserInterface, \Serializable } /** - * Set name + * Set name. + * + * @param string $name * - * @param string $name * @return User */ public function setName($name) @@ -190,7 +234,7 @@ class User implements AdvancedUserInterface, \Serializable } /** - * Get name + * Get name. * * @return string */ @@ -200,9 +244,10 @@ class User implements AdvancedUserInterface, \Serializable } /** - * Set email + * Set email. + * + * @param string $email * - * @param string $email * @return User */ public function setEmail($email) @@ -213,7 +258,7 @@ class User implements AdvancedUserInterface, \Serializable } /** - * Get email + * Get email. * * @return string */ @@ -258,6 +303,25 @@ class User implements AdvancedUserInterface, \Serializable return $this->entries; } + /** + * @param Entry $entry + * + * @return User + */ + public function addTag(Tag $tag) + { + $this->tags[] = $tag; + + return $this; + } + + /** + * @return ArrayCollection + */ + public function getTags() + { + return $this->tags; + } /** * @inheritDoc */ @@ -281,8 +345,7 @@ class User implements AdvancedUserInterface, \Serializable public function unserialize($serialized) { list( - $this->id, - ) = unserialize($serialized); + $this->id) = unserialize($serialized); } public function isEqualTo(UserInterface $user) @@ -309,4 +372,75 @@ class User implements AdvancedUserInterface, \Serializable { 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; + } + + /** + * Set confirmationToken. + * + * @param string $confirmationToken + * + * @return User + */ + public function setConfirmationToken($confirmationToken) + { + $this->confirmationToken = $confirmationToken; + + return $this; + } + + /** + * Get confirmationToken. + * + * @return string + */ + public function getConfirmationToken() + { + return $this->confirmationToken; + } + + /** + * Set passwordRequestedAt. + * + * @param \DateTime $passwordRequestedAt + * + * @return User + */ + public function setPasswordRequestedAt($passwordRequestedAt) + { + $this->passwordRequestedAt = $passwordRequestedAt; + + return $this; + } + + /** + * Get passwordRequestedAt. + * + * @return \DateTime + */ + public function getPasswordRequestedAt() + { + return $this->passwordRequestedAt; + } }