]>
Commit | Line | Data |
---|---|---|
1 | <?php | |
2 | ||
3 | namespace Wallabag\CoreBundle\Entity; | |
4 | ||
5 | use Doctrine\ORM\Mapping as ORM; | |
6 | use Symfony\Component\Security\Core\User\UserInterface; | |
7 | use Symfony\Component\Security\Core\User\AdvancedUserInterface; | |
8 | ||
9 | /** | |
10 | * User | |
11 | * | |
12 | * @ORM\Table(name="user") | |
13 | * @ORM\Entity | |
14 | * @ORM\HasLifecycleCallbacks() | |
15 | */ | |
16 | class User implements AdvancedUserInterface, \Serializable | |
17 | { | |
18 | /** | |
19 | * @var integer | |
20 | * | |
21 | * @ORM\Column(name="id", type="integer") | |
22 | * @ORM\Id | |
23 | * @ORM\GeneratedValue(strategy="AUTO") | |
24 | */ | |
25 | private $id; | |
26 | ||
27 | /** | |
28 | * @var string | |
29 | * | |
30 | * @ORM\Column(name="username", type="text") | |
31 | */ | |
32 | private $username; | |
33 | ||
34 | /** | |
35 | * @var string | |
36 | * | |
37 | * @ORM\Column(type="string", length=32) | |
38 | */ | |
39 | private $salt; | |
40 | ||
41 | /** | |
42 | * @var string | |
43 | * | |
44 | * @ORM\Column(name="password", type="text") | |
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 | ||
62 | /** | |
63 | * @ORM\Column(name="is_active", type="boolean") | |
64 | */ | |
65 | private $isActive; | |
66 | ||
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 | ||
81 | public function __construct() | |
82 | { | |
83 | $this->isActive = true; | |
84 | $this->salt = md5(uniqid(null, true)); | |
85 | } | |
86 | ||
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 | ||
100 | /** | |
101 | * Get id | |
102 | * | |
103 | * @return integer | |
104 | */ | |
105 | public function getId() | |
106 | { | |
107 | return $this->id; | |
108 | } | |
109 | ||
110 | /** | |
111 | * Set username | |
112 | * | |
113 | * @param string $username | |
114 | * @return User | |
115 | */ | |
116 | public function setUsername($username) | |
117 | { | |
118 | $this->username = $username; | |
119 | ||
120 | return $this; | |
121 | } | |
122 | ||
123 | /** | |
124 | * Get username | |
125 | * | |
126 | * @return string | |
127 | */ | |
128 | public function getUsername() | |
129 | { | |
130 | return $this->username; | |
131 | } | |
132 | ||
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 | ||
149 | /** | |
150 | * Set password | |
151 | * | |
152 | * @param string $password | |
153 | * @return User | |
154 | */ | |
155 | public function setPassword($password) | |
156 | { | |
157 | $this->password = $password; | |
158 | ||
159 | return $this; | |
160 | } | |
161 | ||
162 | /** | |
163 | * Get password | |
164 | * | |
165 | * @return string | |
166 | */ | |
167 | public function getPassword() | |
168 | { | |
169 | return $this->password; | |
170 | } | |
171 | ||
172 | /** | |
173 | * Set name | |
174 | * | |
175 | * @param string $name | |
176 | * @return User | |
177 | */ | |
178 | public function setName($name) | |
179 | { | |
180 | $this->name = $name; | |
181 | ||
182 | return $this; | |
183 | } | |
184 | ||
185 | /** | |
186 | * Get name | |
187 | * | |
188 | * @return string | |
189 | */ | |
190 | public function getName() | |
191 | { | |
192 | return $this->name; | |
193 | } | |
194 | ||
195 | /** | |
196 | * Set email | |
197 | * | |
198 | * @param string $email | |
199 | * @return User | |
200 | */ | |
201 | public function setEmail($email) | |
202 | { | |
203 | $this->email = $email; | |
204 | ||
205 | return $this; | |
206 | } | |
207 | ||
208 | /** | |
209 | * Get email | |
210 | * | |
211 | * @return string | |
212 | */ | |
213 | public function getEmail() | |
214 | { | |
215 | return $this->email; | |
216 | } | |
217 | ||
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 | ||
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 | { | |
256 | list( | |
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 | } | |
285 | } |