]>
Commit | Line | Data |
---|---|---|
9d50517c NL |
1 | <?php |
2 | ||
ad4d1caa | 3 | namespace Wallabag\CoreBundle\Entity; |
9d50517c NL |
4 | |
5 | use Doctrine\ORM\Mapping as ORM; | |
c3235553 | 6 | use Symfony\Component\Security\Core\User\UserInterface; |
c3235553 | 7 | use Symfony\Component\Security\Core\User\AdvancedUserInterface; |
9d50517c NL |
8 | |
9 | /** | |
2f69eb4a | 10 | * User |
9d50517c | 11 | * |
2f69eb4a | 12 | * @ORM\Table(name="user") |
9d50517c | 13 | * @ORM\Entity |
2f69eb4a | 14 | * @ORM\HasLifecycleCallbacks() |
9d50517c | 15 | */ |
2f69eb4a | 16 | class User implements AdvancedUserInterface, \Serializable |
9d50517c NL |
17 | { |
18 | /** | |
19 | * @var integer | |
20 | * | |
2f69eb4a | 21 | * @ORM\Column(name="id", type="integer") |
9d50517c | 22 | * @ORM\Id |
2f69eb4a | 23 | * @ORM\GeneratedValue(strategy="AUTO") |
9d50517c NL |
24 | */ |
25 | private $id; | |
26 | ||
27 | /** | |
28 | * @var string | |
29 | * | |
2f69eb4a | 30 | * @ORM\Column(name="username", type="text") |
9d50517c NL |
31 | */ |
32 | private $username; | |
33 | ||
c3235553 | 34 | /** |
2f69eb4a NL |
35 | * @var string |
36 | * | |
c3235553 NL |
37 | * @ORM\Column(type="string", length=32) |
38 | */ | |
39 | private $salt; | |
40 | ||
9d50517c NL |
41 | /** |
42 | * @var string | |
43 | * | |
2f69eb4a | 44 | * @ORM\Column(name="password", type="text") |
9d50517c NL |
45 | */ |
46 | private $password; | |
47 | ||
48 | /** | |
49 | * @var string | |
50 | * | |
51 | * @ORM\Column(name="name", type="text", nullable=true) | |
52 | */ | |
53 | private $name; | |
54 | ||
55 | /** | |
56 | * @var string | |
57 | * | |
58 | * @ORM\Column(name="email", type="text", nullable=true) | |
59 | */ | |
60 | private $email; | |
61 | ||
c3235553 NL |
62 | /** |
63 | * @ORM\Column(name="is_active", type="boolean") | |
64 | */ | |
65 | private $isActive; | |
9d50517c | 66 | |
2f69eb4a NL |
67 | /** |
68 | * @var date | |
69 | * | |
70 | * @ORM\Column(name="created_at", type="datetime") | |
71 | */ | |
72 | private $createdAt; | |
73 | ||
74 | /** | |
75 | * @var date | |
76 | * | |
77 | * @ORM\Column(name="updated_at", type="datetime") | |
78 | */ | |
79 | private $updatedAt; | |
80 | ||
c3235553 NL |
81 | public function __construct() |
82 | { | |
83 | $this->isActive = true; | |
84 | $this->salt = md5(uniqid(null, true)); | |
85 | } | |
9d50517c | 86 | |
2f69eb4a NL |
87 | /** |
88 | * @ORM\PrePersist | |
89 | * @ORM\PreUpdate | |
90 | */ | |
91 | public function timestamps() | |
92 | { | |
93 | if (is_null($this->createdAt)) { | |
94 | $this->createdAt = new \DateTime(); | |
95 | } | |
96 | ||
97 | $this->updatedAt = new \DateTime(); | |
98 | } | |
99 | ||
9d50517c NL |
100 | /** |
101 | * Get id | |
102 | * | |
7df80cb3 | 103 | * @return integer |
9d50517c NL |
104 | */ |
105 | public function getId() | |
106 | { | |
107 | return $this->id; | |
108 | } | |
109 | ||
110 | /** | |
111 | * Set username | |
112 | * | |
7df80cb3 | 113 | * @param string $username |
2f69eb4a | 114 | * @return User |
9d50517c NL |
115 | */ |
116 | public function setUsername($username) | |
117 | { | |
118 | $this->username = $username; | |
119 | ||
120 | return $this; | |
121 | } | |
122 | ||
123 | /** | |
124 | * Get username | |
125 | * | |
7df80cb3 | 126 | * @return string |
9d50517c NL |
127 | */ |
128 | public function getUsername() | |
129 | { | |
130 | return $this->username; | |
131 | } | |
132 | ||
c3235553 NL |
133 | /** |
134 | * @inheritDoc | |
135 | */ | |
136 | public function getSalt() | |
137 | { | |
138 | return $this->salt; | |
139 | } | |
140 | ||
141 | /** | |
142 | * @inheritDoc | |
143 | */ | |
144 | public function getRoles() | |
145 | { | |
146 | return array('ROLE_USER'); | |
147 | } | |
148 | ||
9d50517c NL |
149 | /** |
150 | * Set password | |
151 | * | |
7df80cb3 | 152 | * @param string $password |
2f69eb4a | 153 | * @return User |
9d50517c NL |
154 | */ |
155 | public function setPassword($password) | |
156 | { | |
157 | $this->password = $password; | |
158 | ||
159 | return $this; | |
160 | } | |
161 | ||
162 | /** | |
163 | * Get password | |
164 | * | |
7df80cb3 | 165 | * @return string |
9d50517c NL |
166 | */ |
167 | public function getPassword() | |
168 | { | |
169 | return $this->password; | |
170 | } | |
171 | ||
172 | /** | |
173 | * Set name | |
174 | * | |
7df80cb3 | 175 | * @param string $name |
2f69eb4a | 176 | * @return User |
9d50517c NL |
177 | */ |
178 | public function setName($name) | |
179 | { | |
180 | $this->name = $name; | |
181 | ||
182 | return $this; | |
183 | } | |
184 | ||
185 | /** | |
186 | * Get name | |
187 | * | |
7df80cb3 | 188 | * @return string |
9d50517c NL |
189 | */ |
190 | public function getName() | |
191 | { | |
192 | return $this->name; | |
193 | } | |
194 | ||
195 | /** | |
196 | * Set email | |
197 | * | |
7df80cb3 | 198 | * @param string $email |
2f69eb4a | 199 | * @return User |
9d50517c NL |
200 | */ |
201 | public function setEmail($email) | |
202 | { | |
203 | $this->email = $email; | |
204 | ||
205 | return $this; | |
206 | } | |
207 | ||
208 | /** | |
209 | * Get email | |
210 | * | |
7df80cb3 | 211 | * @return string |
9d50517c NL |
212 | */ |
213 | public function getEmail() | |
214 | { | |
215 | return $this->email; | |
216 | } | |
c3235553 | 217 | |
2f69eb4a NL |
218 | /** |
219 | * @return string | |
220 | */ | |
221 | public function getCreatedAt() | |
222 | { | |
223 | return $this->createdAt; | |
224 | } | |
225 | ||
226 | /** | |
227 | * @return string | |
228 | */ | |
229 | public function getUpdatedAt() | |
230 | { | |
231 | return $this->updatedAt; | |
232 | } | |
233 | ||
c3235553 NL |
234 | /** |
235 | * @inheritDoc | |
236 | */ | |
237 | public function eraseCredentials() | |
238 | { | |
239 | } | |
240 | ||
241 | /** | |
242 | * @see \Serializable::serialize() | |
243 | */ | |
244 | public function serialize() | |
245 | { | |
246 | return serialize(array( | |
247 | $this->id, | |
248 | )); | |
249 | } | |
250 | ||
251 | /** | |
252 | * @see \Serializable::unserialize() | |
253 | */ | |
254 | public function unserialize($serialized) | |
255 | { | |
7df80cb3 | 256 | list( |
c3235553 NL |
257 | $this->id, |
258 | ) = unserialize($serialized); | |
259 | } | |
260 | ||
261 | public function isEqualTo(UserInterface $user) | |
262 | { | |
263 | return $this->username === $user->getUsername(); | |
264 | } | |
265 | ||
266 | public function isAccountNonExpired() | |
267 | { | |
268 | return true; | |
269 | } | |
270 | ||
271 | public function isAccountNonLocked() | |
272 | { | |
273 | return true; | |
274 | } | |
275 | ||
276 | public function isCredentialsNonExpired() | |
277 | { | |
278 | return true; | |
279 | } | |
280 | ||
281 | public function isEnabled() | |
282 | { | |
283 | return $this->isActive; | |
284 | } | |
9d50517c | 285 | } |