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\GuidAwareListener", "PiouPiou\RibsAdminBundle\EventListener\CreateUpdateAwareListener"}) |
11
|
|
|
* @ORM\Table(name="account", uniqueConstraints={@ORM\UniqueConstraint(name="guid_UNIQUE_account", columns={"guid"})}) |
12
|
|
|
*/ |
13
|
|
|
class Account implements UserInterface, \Serializable |
14
|
|
|
{ |
15
|
|
|
use GuidTrait; |
16
|
|
|
use CreatedUpdatedTrait; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @ORM\Id |
20
|
|
|
* @ORM\Column(type="integer") |
21
|
|
|
* @ORM\GeneratedValue(strategy="AUTO") |
22
|
|
|
*/ |
23
|
|
|
protected $id; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @ORM\Column(type="string", length=255, unique=true) |
27
|
|
|
*/ |
28
|
|
|
private $username; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @ORM\Column(type="string", length=64) |
32
|
|
|
*/ |
33
|
|
|
private $password; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @ORM\Column(type="string", length=64, nullable=true) |
37
|
|
|
*/ |
38
|
|
|
private $plainPassword; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @ORM\Column(type="string", length=100, unique=true) |
42
|
|
|
*/ |
43
|
|
|
private $email; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @ORM\Column(name="is_active", type="boolean") |
47
|
|
|
*/ |
48
|
|
|
private $isActive; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @ORM\Column(type="datetime", nullable=true) |
52
|
|
|
*/ |
53
|
|
|
protected $last_connection; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @ORM\OneToMany(targetEntity="AccountToken", mappedBy="account") |
57
|
|
|
* @ORM\JoinColumn(name="id", referencedColumnName="account_id", nullable=false) |
58
|
|
|
*/ |
59
|
|
|
protected $tokens; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @var User |
63
|
|
|
* |
64
|
|
|
* @ORM\OneToOne(targetEntity="PiouPiou\RibsAdminBundle\Entity\User", cascade={"persist"}) |
65
|
|
|
* @ORM\JoinColumns({ |
66
|
|
|
* @ORM\JoinColumn(name="id_user", referencedColumnName="id", nullable=true) |
67
|
|
|
* }) |
68
|
|
|
*/ |
69
|
|
|
private $user; |
70
|
|
|
|
71
|
|
|
public function __construct() |
72
|
|
|
{ |
73
|
|
|
$this->isActive = true; |
74
|
|
|
// may not be needed, see section on salt below |
75
|
|
|
// $this->salt = md5(uniqid('', true)); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @return mixed |
80
|
|
|
*/ |
81
|
|
|
public function getId() |
82
|
|
|
{ |
83
|
|
|
return $this->id; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @param mixed $id |
88
|
|
|
*/ |
89
|
|
|
public function setId($id) |
90
|
|
|
{ |
91
|
|
|
$this->id = $id; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @return mixed |
96
|
|
|
*/ |
97
|
|
|
public function getEmail() |
98
|
|
|
{ |
99
|
|
|
return $this->email; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @param mixed $email |
104
|
|
|
*/ |
105
|
|
|
public function setEmail($email) |
106
|
|
|
{ |
107
|
|
|
$this->email = $email; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @return mixed |
112
|
|
|
*/ |
113
|
|
|
public function getPassword() |
114
|
|
|
{ |
115
|
|
|
return $this->password; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @param mixed $password |
120
|
|
|
*/ |
121
|
|
|
public function setPassword($password) |
122
|
|
|
{ |
123
|
|
|
$this->password = $password; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @return mixed |
128
|
|
|
*/ |
129
|
|
|
public function getPlainPassword() |
130
|
|
|
{ |
131
|
|
|
return $this->plainPassword; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @param mixed $plainPassword |
136
|
|
|
*/ |
137
|
|
|
public function setPlainPassword(string $plainPassword) |
138
|
|
|
{ |
139
|
|
|
$this->plainPassword = $plainPassword; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* @return mixed |
144
|
|
|
*/ |
145
|
|
|
public function getUsername() |
146
|
|
|
{ |
147
|
|
|
return $this->username; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @param mixed $username |
152
|
|
|
*/ |
153
|
|
|
public function setUsername($username) |
154
|
|
|
{ |
155
|
|
|
$this->username = $username; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* @return mixed |
160
|
|
|
*/ |
161
|
|
|
public function getisActive() |
162
|
|
|
{ |
163
|
|
|
return $this->isActive; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* @param mixed $isActive |
168
|
|
|
*/ |
169
|
|
|
public function setIsActive($isActive) |
170
|
|
|
{ |
171
|
|
|
$this->isActive = $isActive; |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* @return User |
176
|
|
|
*/ |
177
|
|
|
public function getUser() |
178
|
|
|
{ |
179
|
|
|
return $this->user; |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
/** |
183
|
|
|
* @param User $user |
184
|
|
|
*/ |
185
|
|
|
public function setUser($user) |
186
|
|
|
{ |
187
|
|
|
$this->user = $user; |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* @return mixed |
192
|
|
|
*/ |
193
|
|
|
public function getLastConnection() |
194
|
|
|
{ |
195
|
|
|
return $this->last_connection; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* @param mixed $last_connection |
200
|
|
|
* @return Account |
201
|
|
|
*/ |
202
|
|
|
public function setLastConnection($last_connection) |
203
|
|
|
{ |
204
|
|
|
$this->last_connection = $last_connection; |
205
|
|
|
|
206
|
|
|
return $this; |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
/** |
210
|
|
|
* @return mixed |
211
|
|
|
*/ |
212
|
|
|
public function getTokens() |
213
|
|
|
{ |
214
|
|
|
return $this->tokens; |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
/** |
218
|
|
|
* @param mixed $tokens |
219
|
|
|
* @return Account |
220
|
|
|
*/ |
221
|
|
|
public function setTokens($tokens) |
222
|
|
|
{ |
223
|
|
|
$this->tokens = $tokens; |
224
|
|
|
|
225
|
|
|
return $this; |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
/** |
229
|
|
|
* Returns the roles granted to the user. |
230
|
|
|
* |
231
|
|
|
* <code> |
232
|
|
|
* public function getRoles() |
233
|
|
|
* { |
234
|
|
|
* return array('ROLE_USER'); |
235
|
|
|
* } |
236
|
|
|
* </code> |
237
|
|
|
* |
238
|
|
|
* Alternatively, the roles might be stored on a ``roles`` property, |
239
|
|
|
* and populated in any number of different ways when the user object |
240
|
|
|
* is created. |
241
|
|
|
* |
242
|
|
|
* @return (Role|string)[] The user roles |
243
|
|
|
*/ |
244
|
|
|
public function getRoles() |
245
|
|
|
{ |
246
|
|
|
return ['ROLE_ADMIN']; |
247
|
|
|
} |
248
|
|
|
|
249
|
|
|
/** |
250
|
|
|
* Returns the salt that was originally used to encode the password. |
251
|
|
|
* |
252
|
|
|
* This can return null if the password was not encoded using a salt. |
253
|
|
|
* |
254
|
|
|
* @return string|null The salt |
255
|
|
|
*/ |
256
|
|
|
public function getSalt() |
257
|
|
|
{ |
258
|
|
|
// you *may* need a real salt depending on your encoder |
259
|
|
|
// see section on salt below |
260
|
|
|
return null; |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
/** |
264
|
|
|
* Removes sensitive data from the user. |
265
|
|
|
* |
266
|
|
|
* This is important if, at any given point, sensitive information like |
267
|
|
|
* the plain-text password is stored on this object. |
268
|
|
|
*/ |
269
|
|
|
public function eraseCredentials() |
270
|
|
|
{ |
271
|
|
|
} |
272
|
|
|
|
273
|
|
|
/** |
274
|
|
|
* String representation of object |
275
|
|
|
* @link http://php.net/manual/en/serializable.serialize.php |
276
|
|
|
* @return string the string representation of the object or null |
277
|
|
|
* @since 5.1.0 |
278
|
|
|
*/ |
279
|
|
|
public function serialize() |
280
|
|
|
{ |
281
|
|
|
return serialize([ |
282
|
|
|
$this->id, |
283
|
|
|
$this->username, |
284
|
|
|
$this->password, |
285
|
|
|
// see section on salt below |
286
|
|
|
// $this->salt, |
287
|
|
|
]); |
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
/** |
291
|
|
|
* Constructs the object |
292
|
|
|
* @link http://php.net/manual/en/serializable.unserialize.php |
293
|
|
|
* @param string $serialized <p> |
294
|
|
|
* The string representation of the object. |
295
|
|
|
* </p> |
296
|
|
|
* @return void |
297
|
|
|
* @since 5.1.0 |
298
|
|
|
*/ |
299
|
|
|
public function unserialize($serialized) |
300
|
|
|
{ |
301
|
|
|
list ( |
302
|
|
|
$this->id, |
303
|
|
|
$this->username, |
304
|
|
|
$this->password, |
305
|
|
|
// see section on salt below |
306
|
|
|
// $this->salt |
307
|
|
|
) = unserialize($serialized); |
308
|
|
|
} |
309
|
|
|
} |
310
|
|
|
|