diff options
author | Nicolas LÅ“uillet <nicolas@loeuillet.org> | 2015-02-09 12:52:06 +0100 |
---|---|---|
committer | Nicolas LÅ“uillet <nicolas@loeuillet.org> | 2015-02-09 12:52:06 +0100 |
commit | 89c03230c3d51e618608b044b0e3f45cf0c06a11 (patch) | |
tree | 504e54ecfd8ae6203f76a19a910e5e6c5dee1c3e /src/Wallabag/CoreBundle/Entity/User.php | |
parent | 8af35ad932177e0363412a868afc128b406e3322 (diff) | |
parent | 3b815d2de5a852fe2ebad5827bd4c9070aa175ea (diff) | |
download | wallabag-89c03230c3d51e618608b044b0e3f45cf0c06a11.tar.gz wallabag-89c03230c3d51e618608b044b0e3f45cf0c06a11.tar.zst wallabag-89c03230c3d51e618608b044b0e3f45cf0c06a11.zip |
Merge pull request #1062 from wallabag/v2-relation-entry-user
add a real relation between user and entry
Diffstat (limited to 'src/Wallabag/CoreBundle/Entity/User.php')
-rw-r--r-- | src/Wallabag/CoreBundle/Entity/User.php | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/src/Wallabag/CoreBundle/Entity/User.php b/src/Wallabag/CoreBundle/Entity/User.php index 6abfd3ae..c83250c3 100644 --- a/src/Wallabag/CoreBundle/Entity/User.php +++ b/src/Wallabag/CoreBundle/Entity/User.php | |||
@@ -2,6 +2,7 @@ | |||
2 | 2 | ||
3 | namespace Wallabag\CoreBundle\Entity; | 3 | namespace Wallabag\CoreBundle\Entity; |
4 | 4 | ||
5 | use Doctrine\Common\Collections\ArrayCollection; | ||
5 | use Doctrine\ORM\Mapping as ORM; | 6 | use Doctrine\ORM\Mapping as ORM; |
6 | use Symfony\Component\Security\Core\User\UserInterface; | 7 | use Symfony\Component\Security\Core\User\UserInterface; |
7 | use Symfony\Component\Security\Core\User\AdvancedUserInterface; | 8 | use Symfony\Component\Security\Core\User\AdvancedUserInterface; |
@@ -78,10 +79,16 @@ class User implements AdvancedUserInterface, \Serializable | |||
78 | */ | 79 | */ |
79 | private $updatedAt; | 80 | private $updatedAt; |
80 | 81 | ||
82 | /** | ||
83 | * @ORM\OneToMany(targetEntity="Entry", mappedBy="user", cascade={"remove"}) | ||
84 | */ | ||
85 | private $entries; | ||
86 | |||
81 | public function __construct() | 87 | public function __construct() |
82 | { | 88 | { |
83 | $this->isActive = true; | 89 | $this->isActive = true; |
84 | $this->salt = md5(uniqid(null, true)); | 90 | $this->salt = md5(uniqid(null, true)); |
91 | $this->entries = new ArrayCollection(); | ||
85 | } | 92 | } |
86 | 93 | ||
87 | /** | 94 | /** |
@@ -154,7 +161,11 @@ class User implements AdvancedUserInterface, \Serializable | |||
154 | */ | 161 | */ |
155 | public function setPassword($password) | 162 | public function setPassword($password) |
156 | { | 163 | { |
157 | $this->password = $password; | 164 | if (!$password && 0 === strlen($password)) { |
165 | return; | ||
166 | } | ||
167 | |||
168 | $this->password = sha1($password.$this->getUsername().$this->getSalt()); | ||
158 | 169 | ||
159 | return $this; | 170 | return $this; |
160 | } | 171 | } |
@@ -232,6 +243,26 @@ class User implements AdvancedUserInterface, \Serializable | |||
232 | } | 243 | } |
233 | 244 | ||
234 | /** | 245 | /** |
246 | * @param Entry $entry | ||
247 | * | ||
248 | * @return User | ||
249 | */ | ||
250 | public function addEntry(Entry $entry) | ||
251 | { | ||
252 | $this->entries[] = $entry; | ||
253 | |||
254 | return $this; | ||
255 | } | ||
256 | |||
257 | /** | ||
258 | * @return ArrayCollection<Entry> | ||
259 | */ | ||
260 | public function getEntries() | ||
261 | { | ||
262 | return $this->entries; | ||
263 | } | ||
264 | |||
265 | /** | ||
235 | * @inheritDoc | 266 | * @inheritDoc |
236 | */ | 267 | */ |
237 | public function eraseCredentials() | 268 | public function eraseCredentials() |