]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/CoreBundle/Entity/User.php
implement FosUser
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Entity / User.php
index c83250c37e6d2a2bec25530c1a92667bc72904d1..eeae331e29582b24752ea30873abee9e0d3ae89b 100644 (file)
@@ -4,91 +4,78 @@ 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;
+use FOS\UserBundle\Model\User as BaseUser;
 
 /**
- * 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
+class User extends BaseUser implements AdvancedUserInterface, \Serializable
 {
     /**
-     * @var integer
+     * @var int
      *
+     * @Expose
      * @ORM\Column(name="id", type="integer")
      * @ORM\Id
      * @ORM\GeneratedValue(strategy="AUTO")
      */
-    private $id;
-
-    /**
-     * @var string
-     *
-     * @ORM\Column(name="username", type="text")
-     */
-    private $username;
-
-    /**
-     * @var string
-     *
-     * @ORM\Column(type="string", length=32)
-     */
-    private $salt;
-
-    /**
-     * @var string
-     *
-     * @ORM\Column(name="password", type="text")
-     */
-    private $password;
+    protected $id;
 
     /**
      * @var string
      *
      * @ORM\Column(name="name", type="text", nullable=true)
      */
-    private $name;
-
-    /**
-     * @var string
-     *
-     * @ORM\Column(name="email", type="text", nullable=true)
-     */
-    private $email;
-
-    /**
-     * @ORM\Column(name="is_active", type="boolean")
-     */
-    private $isActive;
+    protected $name;
 
     /**
      * @var date
      *
      * @ORM\Column(name="created_at", type="datetime")
      */
-    private $createdAt;
+    protected $createdAt;
 
     /**
      * @var date
      *
      * @ORM\Column(name="updated_at", type="datetime")
      */
-    private $updatedAt;
+    protected $updatedAt;
 
     /**
      * @ORM\OneToMany(targetEntity="Entry", mappedBy="user", cascade={"remove"})
      */
-    private $entries;
+    protected $entries;
+
+    /**
+     * @ORM\OneToOne(targetEntity="Config", mappedBy="user")
+     */
+    protected $config;
+
+    /**
+     * @ORM\OneToMany(targetEntity="Tag", mappedBy="user", cascade={"remove"})
+     */
+    protected $tags;
 
     public function __construct()
     {
-        $this->isActive = true;
-        $this->salt     = md5(uniqid(null, true));
+        parent::__construct();
         $this->entries  = new ArrayCollection();
+        $this->tags     = new ArrayCollection();
     }
 
     /**
@@ -105,58 +92,10 @@ class User implements AdvancedUserInterface, \Serializable
     }
 
     /**
-     * Get id
+     * Set password.
      *
-     * @return integer
-     */
-    public function getId()
-    {
-        return $this->id;
-    }
-
-    /**
-     * Set username
+     * @param string $password
      *
-     * @param  string $username
-     * @return User
-     */
-    public function setUsername($username)
-    {
-        $this->username = $username;
-
-        return $this;
-    }
-
-    /**
-     * Get username
-     *
-     * @return string
-     */
-    public function getUsername()
-    {
-        return $this->username;
-    }
-
-    /**
-     * @inheritDoc
-     */
-    public function getSalt()
-    {
-        return $this->salt;
-    }
-
-    /**
-     * @inheritDoc
-     */
-    public function getRoles()
-    {
-        return array('ROLE_USER');
-    }
-
-    /**
-     * Set password
-     *
-     * @param  string $password
      * @return User
      */
     public function setPassword($password)
@@ -171,19 +110,10 @@ class User implements AdvancedUserInterface, \Serializable
     }
 
     /**
-     * Get password
+     * Set name.
      *
-     * @return string
-     */
-    public function getPassword()
-    {
-        return $this->password;
-    }
-
-    /**
-     * Set name
+     * @param string $name
      *
-     * @param  string $name
      * @return User
      */
     public function setName($name)
@@ -194,7 +124,7 @@ class User implements AdvancedUserInterface, \Serializable
     }
 
     /**
-     * Get name
+     * Get name.
      *
      * @return string
      */
@@ -203,29 +133,6 @@ class User implements AdvancedUserInterface, \Serializable
         return $this->name;
     }
 
-    /**
-     * Set email
-     *
-     * @param  string $email
-     * @return User
-     */
-    public function setEmail($email)
-    {
-        $this->email = $email;
-
-        return $this;
-    }
-
-    /**
-     * Get email
-     *
-     * @return string
-     */
-    public function getEmail()
-    {
-        return $this->email;
-    }
-
     /**
      * @return string
      */
@@ -263,30 +170,23 @@ class User implements AdvancedUserInterface, \Serializable
     }
 
     /**
-     * @inheritDoc
+     * @param Entry $entry
+     *
+     * @return User
      */
-    public function eraseCredentials()
+    public function addTag(Tag $tag)
     {
-    }
+        $this->tags[] = $tag;
 
-    /**
-     * @see \Serializable::serialize()
-     */
-    public function serialize()
-    {
-        return serialize(array(
-            $this->id,
-        ));
+        return $this;
     }
 
     /**
-     * @see \Serializable::unserialize()
+     * @return ArrayCollection<Tag>
      */
-    public function unserialize($serialized)
+    public function getTags()
     {
-        list(
-            $this->id,
-            ) = unserialize($serialized);
+        return $this->tags;
     }
 
     public function isEqualTo(UserInterface $user)
@@ -294,23 +194,27 @@ class User implements AdvancedUserInterface, \Serializable
         return $this->username === $user->getUsername();
     }
 
-    public function isAccountNonExpired()
-    {
-        return true;
-    }
-
-    public function isAccountNonLocked()
+    /**
+     * Set config.
+     *
+     * @param \Wallabag\CoreBundle\Entity\Config $config
+     *
+     * @return User
+     */
+    public function setConfig(\Wallabag\CoreBundle\Entity\Config $config = null)
     {
-        return true;
-    }
+        $this->config = $config;
 
-    public function isCredentialsNonExpired()
-    {
-        return true;
+        return $this;
     }
 
-    public function isEnabled()
+    /**
+     * Get config.
+     *
+     * @return \Wallabag\CoreBundle\Entity\Config
+     */
+    public function getConfig()
     {
-        return $this->isActive;
+        return $this->config;
     }
 }