1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace App\User\Persistence\Entity; |
5
|
|
|
|
6
|
|
|
use Doctrine\ORM\Mapping as ORM; |
7
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
8
|
|
|
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; |
9
|
|
|
use Symfony\Component\Security\Core\User\UserInterface; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @ORM\Table(name="app_users") |
13
|
|
|
* @ORM\Entity(repositoryClass="App\User\Persistence\Repository\UserRepository") |
14
|
|
|
* @UniqueEntity(fields="email", message="Email already taken") |
15
|
|
|
* @UniqueEntity(fields="username", message="Username already taken") |
16
|
|
|
*/ |
17
|
|
|
class User implements UserInterface, \Serializable |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @ORM\Id |
21
|
|
|
* @ORM\Column(type="integer") |
22
|
|
|
* @ORM\GeneratedValue(strategy="AUTO") |
23
|
|
|
*/ |
24
|
|
|
private $id; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @ORM\Column(type="string", length=255, unique=true) |
28
|
|
|
* @Assert\NotBlank() |
29
|
|
|
* @Assert\Email() |
30
|
|
|
*/ |
31
|
|
|
private $email; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @ORM\Column(type="string", length=255, unique=true) |
35
|
|
|
* @Assert\NotBlank() |
36
|
|
|
*/ |
37
|
|
|
private $username; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @Assert\NotBlank() |
41
|
|
|
* @Assert\Length(max=4096) |
42
|
|
|
*/ |
43
|
|
|
private $plainPassword; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* The below length depends on the "algorithm" you use for encoding |
47
|
|
|
* the password, but this works well with bcrypt. |
48
|
|
|
* |
49
|
|
|
* @ORM\Column(type="string", length=64) |
50
|
|
|
*/ |
51
|
|
|
private $password; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @ORM\Column(name="is_active", type="boolean") |
55
|
|
|
*/ |
56
|
|
|
private $isActive; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @ORM\Column(type="array") |
60
|
|
|
*/ |
61
|
|
|
private $roles; |
62
|
|
|
|
63
|
|
|
public function __construct() |
64
|
|
|
{ |
65
|
|
|
$this->isActive = true; |
66
|
|
|
$this->roles = array('ROLE_USER'); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function getId() |
70
|
|
|
{ |
71
|
|
|
return $this->id; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
|
75
|
|
|
public function getUsername() |
76
|
|
|
{ |
77
|
|
|
return $this->username; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function getSalt() |
81
|
|
|
{ |
82
|
|
|
return null; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function getPassword() |
86
|
|
|
{ |
87
|
|
|
return $this->password; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @return mixed |
92
|
|
|
*/ |
93
|
|
|
public function getEmail() |
94
|
|
|
{ |
95
|
|
|
return $this->email; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
|
99
|
|
|
public function getRoles() |
100
|
|
|
{ |
101
|
|
|
return $this->roles; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
|
105
|
|
|
public function eraseCredentials() |
106
|
|
|
{ |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @return mixed |
111
|
|
|
*/ |
112
|
|
|
public function getPlainPassword() |
113
|
|
|
{ |
114
|
|
|
return $this->plainPassword; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @param mixed $email |
119
|
|
|
*/ |
120
|
|
|
public function setEmail($email): void |
121
|
|
|
{ |
122
|
|
|
$this->email = $email; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @param mixed $username |
127
|
|
|
*/ |
128
|
|
|
public function setUsername($username): void |
129
|
|
|
{ |
130
|
|
|
$this->username = $username; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* @param mixed $plainPassword |
135
|
|
|
*/ |
136
|
|
|
public function setPlainPassword($plainPassword): void |
137
|
|
|
{ |
138
|
|
|
$this->plainPassword = $plainPassword; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* @param mixed $password |
143
|
|
|
*/ |
144
|
|
|
public function setPassword($password): void |
145
|
|
|
{ |
146
|
|
|
$this->password = $password; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
|
150
|
|
|
/** @see \Serializable::serialize() */ |
151
|
|
|
public function serialize() |
152
|
|
|
{ |
153
|
|
|
return serialize(array( |
154
|
|
|
$this->id, |
155
|
|
|
$this->username, |
156
|
|
|
$this->password, |
157
|
|
|
$this->email, |
158
|
|
|
// see section on salt below |
159
|
|
|
// $this->salt, |
160
|
|
|
)); |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** @see \Serializable::unserialize() */ |
164
|
|
|
public function unserialize($serialized) |
165
|
|
|
{ |
166
|
|
|
list ( |
167
|
|
|
$this->id, |
168
|
|
|
$this->username, |
169
|
|
|
$this->password, |
170
|
|
|
$this->email, |
171
|
|
|
// see section on salt below |
172
|
|
|
// $this->salt |
173
|
|
|
) = unserialize($serialized, ['allowed_classes' => false]); |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
} |