aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Entity/Users.php
diff options
context:
space:
mode:
authorNicolas LÅ“uillet <nicolas@loeuillet.org>2015-01-31 15:14:10 +0100
committerNicolas LÅ“uillet <nicolas@loeuillet.org>2015-01-31 15:14:10 +0100
commitc3235553ddc2bb5965f6fe00e750cfe4aac9ccdf (patch)
tree271305a039d31059c7af8be220da08b9331baeec /src/Wallabag/CoreBundle/Entity/Users.php
parent71691fe44a7b2a80f3b9d96d54720cce7994ad08 (diff)
downloadwallabag-c3235553ddc2bb5965f6fe00e750cfe4aac9ccdf.tar.gz
wallabag-c3235553ddc2bb5965f6fe00e750cfe4aac9ccdf.tar.zst
wallabag-c3235553ddc2bb5965f6fe00e750cfe4aac9ccdf.zip
first implementation of security
Diffstat (limited to 'src/Wallabag/CoreBundle/Entity/Users.php')
-rw-r--r--src/Wallabag/CoreBundle/Entity/Users.php87
1 files changed, 86 insertions, 1 deletions
diff --git a/src/Wallabag/CoreBundle/Entity/Users.php b/src/Wallabag/CoreBundle/Entity/Users.php
index 3db4a3fd..96867bd6 100644
--- a/src/Wallabag/CoreBundle/Entity/Users.php
+++ b/src/Wallabag/CoreBundle/Entity/Users.php
@@ -3,6 +3,9 @@
3namespace Wallabag\CoreBundle\Entity; 3namespace Wallabag\CoreBundle\Entity;
4 4
5use Doctrine\ORM\Mapping as ORM; 5use Doctrine\ORM\Mapping as ORM;
6use Symfony\Component\Security\Core\User\UserInterface;
7use Symfony\Component\Security\Core\User\EquatableInterface;
8use Symfony\Component\Security\Core\User\AdvancedUserInterface;
6 9
7/** 10/**
8 * Users 11 * Users
@@ -10,7 +13,7 @@ use Doctrine\ORM\Mapping as ORM;
10 * @ORM\Table(name="users") 13 * @ORM\Table(name="users")
11 * @ORM\Entity 14 * @ORM\Entity
12 */ 15 */
13class Users 16class Users implements AdvancedUserInterface, \Serializable
14{ 17{
15 /** 18 /**
16 * @var integer 19 * @var integer
@@ -29,6 +32,11 @@ class Users
29 private $username; 32 private $username;
30 33
31 /** 34 /**
35 * @ORM\Column(type="string", length=32)
36 */
37 private $salt;
38
39 /**
32 * @var string 40 * @var string
33 * 41 *
34 * @ORM\Column(name="password", type="text", nullable=true) 42 * @ORM\Column(name="password", type="text", nullable=true)
@@ -49,7 +57,16 @@ class Users
49 */ 57 */
50 private $email; 58 private $email;
51 59
60 /**
61 * @ORM\Column(name="is_active", type="boolean")
62 */
63 private $isActive;
52 64
65 public function __construct()
66 {
67 $this->isActive = true;
68 $this->salt = md5(uniqid(null, true));
69 }
53 70
54 /** 71 /**
55 * Get id 72 * Get id
@@ -85,6 +102,22 @@ class Users
85 } 102 }
86 103
87 /** 104 /**
105 * @inheritDoc
106 */
107 public function getSalt()
108 {
109 return $this->salt;
110 }
111
112 /**
113 * @inheritDoc
114 */
115 public function getRoles()
116 {
117 return array('ROLE_USER');
118 }
119
120 /**
88 * Set password 121 * Set password
89 * 122 *
90 * @param string $password 123 * @param string $password
@@ -152,4 +185,56 @@ class Users
152 { 185 {
153 return $this->email; 186 return $this->email;
154 } 187 }
188
189 /**
190 * @inheritDoc
191 */
192 public function eraseCredentials()
193 {
194 }
195
196 /**
197 * @see \Serializable::serialize()
198 */
199 public function serialize()
200 {
201 return serialize(array(
202 $this->id,
203 ));
204 }
205
206 /**
207 * @see \Serializable::unserialize()
208 */
209 public function unserialize($serialized)
210 {
211 list (
212 $this->id,
213 ) = unserialize($serialized);
214 }
215
216 public function isEqualTo(UserInterface $user)
217 {
218 return $this->username === $user->getUsername();
219 }
220
221 public function isAccountNonExpired()
222 {
223 return true;
224 }
225
226 public function isAccountNonLocked()
227 {
228 return true;
229 }
230
231 public function isCredentialsNonExpired()
232 {
233 return true;
234 }
235
236 public function isEnabled()
237 {
238 return $this->isActive;
239 }
155} 240}