1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PiouPiou\RibsAdminBundle\Entity; |
4
|
|
|
|
5
|
|
|
use Doctrine\ORM\Mapping as ORM; |
6
|
|
|
use Symfony\Component\Security\Core\User\UserInterface; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* @ORM\Entity(repositoryClass="PiouPiou\RibsAdminBundle\Repository\AccountRepository") |
10
|
|
|
* @ORM\EntityListeners({"PiouPiou\RibsAdminBundle\EventListener\CreateUpdateAwareListener"}) |
11
|
|
|
* @ORM\Table(name="account") |
12
|
|
|
*/ |
13
|
|
|
class Account implements UserInterface, \Serializable |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @ORM\Id |
17
|
|
|
* @ORM\Column(type="integer") |
18
|
|
|
* @ORM\GeneratedValue(strategy="AUTO") |
19
|
|
|
*/ |
20
|
|
|
protected $id; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @ORM\Column(type="string", length=255, unique=true) |
24
|
|
|
*/ |
25
|
|
|
private $username; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @ORM\Column(type="string", length=64) |
29
|
|
|
*/ |
30
|
|
|
private $password; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @ORM\Column(type="string", length=64, nullable=true) |
34
|
|
|
*/ |
35
|
|
|
private $plainPassword; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @ORM\Column(type="string", length=100, unique=true) |
39
|
|
|
*/ |
40
|
|
|
private $email; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @ORM\Column(name="is_active", type="boolean") |
44
|
|
|
*/ |
45
|
|
|
private $isActive; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @ORM\Column(type="datetime", nullable=true) |
49
|
|
|
*/ |
50
|
|
|
protected $last_connection; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @ORM\OneToMany(targetEntity="AccountToken", mappedBy="account") |
54
|
|
|
* @ORM\JoinColumn(name="id", referencedColumnName="account_id", nullable=false) |
55
|
|
|
*/ |
56
|
|
|
protected $tokens; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @var User |
60
|
|
|
* |
61
|
|
|
* @ORM\OneToOne(targetEntity="PiouPiou\RibsAdminBundle\Entity\User", cascade={"persist"}) |
62
|
|
|
* @ORM\JoinColumns({ |
63
|
|
|
* @ORM\JoinColumn(name="id_user", referencedColumnName="id", nullable=true) |
64
|
|
|
* }) |
65
|
|
|
*/ |
66
|
|
|
private $user; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @ORM\Column(name="created_at", type="datetime", nullable=true) |
70
|
|
|
*/ |
71
|
|
|
protected $created_at; |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @ORM\Column(name="created_by", type="integer", nullable=false) |
75
|
|
|
* @ORM\ManyToOne(targetEntity="PiouPiou\RibsAdminBundle\Entity\User") |
76
|
|
|
* @ORM\JoinColumn(name="created_by", referencedColumnName="id", nullable=false) |
77
|
|
|
*/ |
78
|
|
|
protected $created_by; |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @ORM\Column(name="updated_at", type="datetime", nullable=true) |
82
|
|
|
*/ |
83
|
|
|
protected $updated_at; |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @ORM\Column(name="updated_by", type="integer", nullable=false) |
87
|
|
|
* @ORM\ManyToOne(targetEntity="PiouPiou\RibsAdminBundle\Entity\User") |
88
|
|
|
* @ORM\JoinColumn(name="updated_by", referencedColumnName="id", nullable=false) |
89
|
|
|
*/ |
90
|
|
|
protected $updated_by; |
91
|
|
|
|
92
|
|
|
public function __construct() |
93
|
|
|
{ |
94
|
|
|
$this->isActive = true; |
95
|
|
|
// may not be needed, see section on salt below |
96
|
|
|
// $this->salt = md5(uniqid('', true)); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @return mixed |
101
|
|
|
*/ |
102
|
|
|
public function getId() |
103
|
|
|
{ |
104
|
|
|
return $this->id; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @param mixed $id |
109
|
|
|
*/ |
110
|
|
|
public function setId($id) |
111
|
|
|
{ |
112
|
|
|
$this->id = $id; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @return mixed |
117
|
|
|
*/ |
118
|
|
|
public function getEmail() |
119
|
|
|
{ |
120
|
|
|
return $this->email; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @param mixed $email |
125
|
|
|
*/ |
126
|
|
|
public function setEmail($email) |
127
|
|
|
{ |
128
|
|
|
$this->email = $email; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* @return mixed |
133
|
|
|
*/ |
134
|
|
|
public function getPassword() |
135
|
|
|
{ |
136
|
|
|
return $this->password; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* @param mixed $password |
141
|
|
|
*/ |
142
|
|
|
public function setPassword($password) |
143
|
|
|
{ |
144
|
|
|
$this->password = $password; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* @return mixed |
149
|
|
|
*/ |
150
|
|
|
public function getPlainPassword() |
151
|
|
|
{ |
152
|
|
|
return $this->plainPassword; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* @param mixed $plainPassword |
157
|
|
|
*/ |
158
|
|
|
public function setPlainPassword(string $plainPassword) |
159
|
|
|
{ |
160
|
|
|
$this->plainPassword = $plainPassword; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* @return mixed |
165
|
|
|
*/ |
166
|
|
|
public function getUsername() |
167
|
|
|
{ |
168
|
|
|
return $this->username; |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* @param mixed $username |
173
|
|
|
*/ |
174
|
|
|
public function setUsername($username) |
175
|
|
|
{ |
176
|
|
|
$this->username = $username; |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* @return mixed |
181
|
|
|
*/ |
182
|
|
|
public function getisActive() |
183
|
|
|
{ |
184
|
|
|
return $this->isActive; |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* @param mixed $isActive |
189
|
|
|
*/ |
190
|
|
|
public function setIsActive($isActive) |
191
|
|
|
{ |
192
|
|
|
$this->isActive = $isActive; |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* @return User |
197
|
|
|
*/ |
198
|
|
|
public function getUser() |
199
|
|
|
{ |
200
|
|
|
return $this->user; |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
/** |
204
|
|
|
* @param User $user |
205
|
|
|
*/ |
206
|
|
|
public function setUser($user) |
207
|
|
|
{ |
208
|
|
|
$this->user = $user; |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
/** |
212
|
|
|
* @return mixed |
213
|
|
|
*/ |
214
|
|
|
public function getLastConnection() |
215
|
|
|
{ |
216
|
|
|
return $this->last_connection; |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
/** |
220
|
|
|
* @param mixed $last_connection |
221
|
|
|
* @return Account |
222
|
|
|
*/ |
223
|
|
|
public function setLastConnection($last_connection) |
224
|
|
|
{ |
225
|
|
|
$this->last_connection = $last_connection; |
226
|
|
|
|
227
|
|
|
return $this; |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
/** |
231
|
|
|
* @return mixed |
232
|
|
|
*/ |
233
|
|
|
public function getTokens() |
234
|
|
|
{ |
235
|
|
|
return $this->tokens; |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
/** |
239
|
|
|
* @param mixed $tokens |
240
|
|
|
* @return Account |
241
|
|
|
*/ |
242
|
|
|
public function setTokens($tokens) |
243
|
|
|
{ |
244
|
|
|
$this->tokens = $tokens; |
245
|
|
|
|
246
|
|
|
return $this; |
247
|
|
|
} |
248
|
|
|
|
249
|
|
|
/** |
250
|
|
|
* Returns the roles granted to the user. |
251
|
|
|
* |
252
|
|
|
* <code> |
253
|
|
|
* public function getRoles() |
254
|
|
|
* { |
255
|
|
|
* return array('ROLE_USER'); |
256
|
|
|
* } |
257
|
|
|
* </code> |
258
|
|
|
* |
259
|
|
|
* Alternatively, the roles might be stored on a ``roles`` property, |
260
|
|
|
* and populated in any number of different ways when the user object |
261
|
|
|
* is created. |
262
|
|
|
* |
263
|
|
|
* @return (Role|string)[] The user roles |
264
|
|
|
*/ |
265
|
|
|
public function getRoles() |
266
|
|
|
{ |
267
|
|
|
return ['ROLE_ADMIN']; |
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
/** |
271
|
|
|
* Returns the salt that was originally used to encode the password. |
272
|
|
|
* |
273
|
|
|
* This can return null if the password was not encoded using a salt. |
274
|
|
|
* |
275
|
|
|
* @return string|null The salt |
276
|
|
|
*/ |
277
|
|
|
public function getSalt() |
278
|
|
|
{ |
279
|
|
|
// you *may* need a real salt depending on your encoder |
280
|
|
|
// see section on salt below |
281
|
|
|
return null; |
282
|
|
|
} |
283
|
|
|
|
284
|
|
|
/** |
285
|
|
|
* Removes sensitive data from the user. |
286
|
|
|
* |
287
|
|
|
* This is important if, at any given point, sensitive information like |
288
|
|
|
* the plain-text password is stored on this object. |
289
|
|
|
*/ |
290
|
|
|
public function eraseCredentials() |
291
|
|
|
{ |
292
|
|
|
} |
293
|
|
|
|
294
|
|
|
/** |
295
|
|
|
* String representation of object |
296
|
|
|
* @link http://php.net/manual/en/serializable.serialize.php |
297
|
|
|
* @return string the string representation of the object or null |
298
|
|
|
* @since 5.1.0 |
299
|
|
|
*/ |
300
|
|
|
public function serialize() |
301
|
|
|
{ |
302
|
|
|
return serialize([ |
303
|
|
|
$this->id, |
304
|
|
|
$this->username, |
305
|
|
|
$this->password, |
306
|
|
|
// see section on salt below |
307
|
|
|
// $this->salt, |
308
|
|
|
]); |
309
|
|
|
} |
310
|
|
|
|
311
|
|
|
/** |
312
|
|
|
* Constructs the object |
313
|
|
|
* @link http://php.net/manual/en/serializable.unserialize.php |
314
|
|
|
* @param string $serialized <p> |
315
|
|
|
* The string representation of the object. |
316
|
|
|
* </p> |
317
|
|
|
* @return void |
318
|
|
|
* @since 5.1.0 |
319
|
|
|
*/ |
320
|
|
|
public function unserialize($serialized) |
321
|
|
|
{ |
322
|
|
|
list ( |
323
|
|
|
$this->id, |
324
|
|
|
$this->username, |
325
|
|
|
$this->password, |
326
|
|
|
// see section on salt below |
327
|
|
|
// $this->salt |
328
|
|
|
) = unserialize($serialized); |
329
|
|
|
} |
330
|
|
|
|
331
|
|
|
/** |
332
|
|
|
* @return mixed |
333
|
|
|
*/ |
334
|
|
|
public function getCreatedAt() |
335
|
|
|
{ |
336
|
|
|
return $this->created_at; |
337
|
|
|
} |
338
|
|
|
|
339
|
|
|
/** |
340
|
|
|
* @param mixed $created_at |
341
|
|
|
* @return Account |
342
|
|
|
*/ |
343
|
|
|
public function setCreatedAt($created_at): Account |
344
|
|
|
{ |
345
|
|
|
$this->created_at = $created_at; |
346
|
|
|
|
347
|
|
|
return $this; |
348
|
|
|
} |
349
|
|
|
|
350
|
|
|
/** |
351
|
|
|
* @return mixed |
352
|
|
|
*/ |
353
|
|
|
public function getCreatedBy() |
354
|
|
|
{ |
355
|
|
|
return $this->created_by; |
356
|
|
|
} |
357
|
|
|
|
358
|
|
|
/** |
359
|
|
|
* @ORM\PrePersist |
360
|
|
|
* @param mixed $created_by |
361
|
|
|
* @return Account |
362
|
|
|
*/ |
363
|
|
|
public function setCreatedBy($created_by): Account |
364
|
|
|
{ |
365
|
|
|
$this->created_by = $created_by; |
366
|
|
|
|
367
|
|
|
return $this; |
368
|
|
|
} |
369
|
|
|
|
370
|
|
|
/** |
371
|
|
|
* @return mixed |
372
|
|
|
*/ |
373
|
|
|
public function getUpdatedAt() |
374
|
|
|
{ |
375
|
|
|
return $this->updated_at; |
376
|
|
|
} |
377
|
|
|
|
378
|
|
|
/** |
379
|
|
|
* @param mixed $updated_at |
380
|
|
|
* @return Account |
381
|
|
|
*/ |
382
|
|
|
public function setUpdatedAt($updated_at): Account |
383
|
|
|
{ |
384
|
|
|
$this->updated_at = $updated_at; |
385
|
|
|
|
386
|
|
|
return $this; |
387
|
|
|
} |
388
|
|
|
|
389
|
|
|
/** |
390
|
|
|
* @return mixed |
391
|
|
|
*/ |
392
|
|
|
public function getUpdatedBy() |
393
|
|
|
{ |
394
|
|
|
return $this->updated_by; |
395
|
|
|
} |
396
|
|
|
|
397
|
|
|
/** |
398
|
|
|
* @ORM\PreUpdate |
399
|
|
|
* @param mixed $updated_by |
400
|
|
|
* @return Account |
401
|
|
|
*/ |
402
|
|
|
public function setUpdatedBy($updated_by): Account |
403
|
|
|
{ |
404
|
|
|
$this->updated_by = $updated_by; |
405
|
|
|
|
406
|
|
|
return $this; |
407
|
|
|
} |
408
|
|
|
} |
409
|
|
|
|