1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Entity; |
4
|
|
|
|
5
|
|
|
use App\Model\CourseInterface; |
6
|
|
|
use App\Model\PersistableAwareTrait; |
7
|
|
|
use App\Model\TimestampableAwareTrait; |
8
|
|
|
use App\Model\UserInterface; |
9
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
10
|
|
|
use Doctrine\Common\Collections\Collection; |
11
|
|
|
|
12
|
|
|
class User implements UserInterface |
13
|
|
|
{ |
14
|
|
|
use TimestampableAwareTrait, PersistableAwareTrait; |
15
|
|
|
|
16
|
|
|
private $email; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var string[] |
20
|
|
|
*/ |
21
|
|
|
private $roles = []; |
22
|
|
|
|
23
|
|
|
private $password; |
24
|
|
|
|
25
|
|
|
private $firstName; |
26
|
|
|
|
27
|
|
|
private $lastName; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var string|null Temporary field used for password hashing |
31
|
|
|
*/ |
32
|
|
|
private $plainPassword; |
33
|
|
|
|
34
|
|
|
private $passwordNeedToBeChanged; |
35
|
|
|
|
36
|
|
|
private $passwordResetToken; |
37
|
|
|
|
38
|
|
|
private $courses; |
39
|
|
|
|
40
|
|
|
public function __construct() |
41
|
|
|
{ |
42
|
|
|
$this->courses = new ArrayCollection(); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function getEmail(): ?string |
46
|
|
|
{ |
47
|
|
|
return $this->email; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function setEmail(string $email): void |
51
|
|
|
{ |
52
|
|
|
$this->email = $email; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function getUsername(): string |
56
|
|
|
{ |
57
|
|
|
return (string) $this->email; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function getRoles(): array |
61
|
|
|
{ |
62
|
|
|
$roles = $this->roles; |
63
|
|
|
$roles[] = 'ROLE_USER'; |
64
|
|
|
|
65
|
|
|
return array_unique($roles); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function setRoles(array $roles): void |
69
|
|
|
{ |
70
|
|
|
$this->roles = $roles; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function getPassword(): string |
74
|
|
|
{ |
75
|
|
|
return (string) $this->password; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function setPassword(string $password): void |
79
|
|
|
{ |
80
|
|
|
$this->password = $password; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function getPlainPassword(): ?string |
84
|
|
|
{ |
85
|
|
|
return $this->plainPassword; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function setPlainPassword(?string $plainPassword): void |
89
|
|
|
{ |
90
|
|
|
$this->plainPassword = $plainPassword; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
public function getSalt(): ?string |
94
|
|
|
{ |
95
|
|
|
return null; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public function eraseCredentials() |
99
|
|
|
{ |
100
|
|
|
$this->plainPassword = null; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
public function getFirstName(): ?string |
104
|
|
|
{ |
105
|
|
|
return $this->firstName; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
public function setFirstName(string $firstName): void |
109
|
|
|
{ |
110
|
|
|
$this->firstName = $firstName; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
public function getLastName(): ?string |
114
|
|
|
{ |
115
|
|
|
return $this->lastName; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
public function setLastName(string $lastName): void |
119
|
|
|
{ |
120
|
|
|
$this->lastName = $lastName; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
public function getCourses(): Collection |
124
|
|
|
{ |
125
|
|
|
return $this->courses; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
public function addCourse(CourseInterface $course): void |
129
|
|
|
{ |
130
|
|
|
if (!$this->courses->contains($course)) { |
131
|
|
|
$this->courses->add($course); |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
public function removeCourse(CourseInterface $course): void |
136
|
|
|
{ |
137
|
|
|
if ($this->courses->contains($course)) { |
138
|
|
|
$this->courses->removeElement($course); |
139
|
|
|
} |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
public function getPasswordNeedToBeChanged(): ?bool |
143
|
|
|
{ |
144
|
|
|
return $this->passwordNeedToBeChanged; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
public function setPasswordNeedToBeChanged($passwordNeedToBeChanged): void |
148
|
|
|
{ |
149
|
|
|
$this->passwordNeedToBeChanged = $passwordNeedToBeChanged; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
public function getPasswordResetToken(): ?string |
153
|
|
|
{ |
154
|
|
|
return $this->passwordResetToken; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
public function setPasswordResetToken(?string $passwordResetToken): void |
158
|
|
|
{ |
159
|
|
|
$this->passwordResetToken = $passwordResetToken; |
160
|
|
|
} |
161
|
|
|
} |
162
|
|
|
|