1 | <?php |
||
20 | class User implements UserInterface, \Serializable |
||
21 | { |
||
22 | const ROLE_USER = 'ROLE_USER'; |
||
23 | const ROLE_ADMIN = 'ROLE_ADMIN'; |
||
24 | |||
25 | /** |
||
26 | * @ORM\Id() |
||
27 | * @ORM\GeneratedValue() |
||
28 | * @ORM\Column(type="integer") |
||
29 | */ |
||
30 | private $id; |
||
31 | |||
32 | #private $tokens; |
||
33 | |||
34 | /** |
||
35 | * @var $profile UserProfile |
||
36 | * @ORM\OneToOne(targetEntity="App\Entity\UserProfile", cascade={"persist", "remove"}) |
||
37 | */ |
||
38 | private $profile; |
||
39 | |||
40 | /** |
||
41 | * @ORM\Column(type="string", length=255, unique=true) |
||
42 | */ |
||
43 | public $email; |
||
44 | |||
45 | /** |
||
46 | * @ORM\Column(type="integer", length=1, options={"default" : 0}) |
||
47 | */ |
||
48 | private $isEmailConfirmed = 0; |
||
49 | |||
50 | /** |
||
51 | * @ORM\Column(type="string", length=255, unique=true) |
||
52 | */ |
||
53 | public $username; |
||
54 | |||
55 | /** |
||
56 | * @ORM\Column(type="string", length=255, nullable=true) |
||
57 | */ |
||
58 | private $roles; |
||
59 | |||
60 | /** |
||
61 | * @Exclude |
||
62 | */ |
||
63 | private $plainPassword; |
||
64 | |||
65 | /** |
||
66 | * @Exclude |
||
67 | * @ORM\Column(type="string", length=64) |
||
68 | */ |
||
69 | private $password; |
||
70 | |||
71 | 31 | public function __construct() |
|
72 | { |
||
73 | 31 | $this->addRole(self::ROLE_USER); |
|
74 | 31 | $this->profile = new UserProfile($this); |
|
75 | 31 | } |
|
76 | |||
77 | 8 | public function getProfile(): UserProfile |
|
81 | |||
82 | 4 | public function getId(): ?int |
|
86 | |||
87 | 31 | public function addRole(string $role): self |
|
88 | { |
||
89 | 31 | if (array_search($role, $this->getRoles()) === false) { |
|
90 | 3 | return $this->setRoles( |
|
91 | 3 | array_merge($this->getRoles(), [$role]) |
|
92 | ); |
||
93 | } |
||
94 | |||
95 | 31 | return $this; |
|
96 | } |
||
97 | |||
98 | 1 | public function removeRole(string $role): self |
|
110 | |||
111 | 3 | private function setRoles(array $roles): self |
|
112 | { |
||
113 | 3 | if (!count($roles)) { |
|
114 | 1 | $this->roles = null; |
|
115 | 1 | return $this; |
|
116 | } |
||
117 | |||
118 | 3 | $this->roles = json_encode($roles); |
|
119 | |||
120 | 3 | return $this; |
|
121 | } |
||
122 | |||
123 | 35 | public function getRoles(): array |
|
137 | |||
138 | 33 | private function getDefaultRoles() |
|
142 | |||
143 | 5 | public function setPlainPassword(string $plainPassword): self |
|
153 | |||
154 | 7 | public function getPlainPassword(): string |
|
158 | |||
159 | 9 | public function setPassword($password, UserPasswordEncoderInterface $passwordEncoder): self |
|
165 | |||
166 | 6 | public function isPasswordValid($password, UserPasswordEncoderInterface $passwordEncoder): bool |
|
170 | |||
171 | 4 | public function getPassword(): ?string |
|
175 | |||
176 | 11 | public function getSalt(): ?string |
|
180 | |||
181 | 7 | public function getUsername(): ?string |
|
185 | |||
186 | 10 | public function eraseCredentials(): self |
|
192 | |||
193 | 1 | public function serialize(): string |
|
202 | |||
203 | 1 | public function unserialize($serialized): self |
|
214 | |||
215 | 1 | public function confirmEmail() |
|
221 | |||
222 | public function changeEmail($email) |
||
229 | } |