User::getSalt()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 0
dl 0
loc 2
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace App\Entity;
4
5
use Doctrine\Common\Collections\ArrayCollection;
6
use Doctrine\Common\Collections\Collection;
7
use Doctrine\ORM\Mapping as ORM;
8
use Symfony\Component\Security\Core\User\UserInterface;
9
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
10
use Symfony\Component\Validator\Constraints as Assert;
11
use ApiPlatform\Core\Annotation\ApiResource;
12
13
14
/**
15
 * @ORM\Entity(repositoryClass="App\Repository\UserRepository")
16
 *
17
 * @UniqueEntity(
18
 *     fields={"email"},
19
 *     message="Cet email est déjà pris"
20
 * )
21
 *
22
 * @UniqueEntity(
23
 *      fields={"username"},
24
 *      message="Ce pseudo est déjà pris"
25
 * )
26
 */
27
class User implements UserInterface
28
{
29
    /**
30
     * @ORM\Id()
31
     * @ORM\GeneratedValue()
32
     * @ORM\Column(type="integer")
33
     */
34
    private $id;
35
36
    /**
37
     * @ORM\Column(type="string", length=180, unique=true)
38
     * @Assert\Email(message = "Veuillez entrer un email valide")
39
     */
40
    private $email;
41
42
    /**
43
     * @ORM\Column(type="json")
44
     */
45
    private $roles = [];
46
47
    /**
48
     * @Assert\Length(min="5", minMessage="Votre mot de passe doit faire minimum 5 caractères", max=4096)
49
     */
50
    private $plainPassword;
51
52
    /**
53
     * @var string The hashed password
54
     * @ORM\Column(type="string")
55
     * @Assert\Length(min="5", minMessage="Votre mot de passe doit faire minimum 5 caractères", max=4096)
56
     */
57
    private $password;
58
59
    /**
60
     * @ORM\Column(type="string", length=255, unique=true)
61
     * @Assert\Length(min="5", minMessage="Votre pseudo doit faire minimum 5 caractères")
62
     */
63
    private $username;
64
65
    /**
66
     * @ORM\OneToMany(targetEntity="App\Entity\Advert", mappedBy="author", orphanRemoval=true)
67
     */
68
    private $adverts;
69
70
    /**
71
     * @ORM\OneToMany(targetEntity="App\Entity\Application", mappedBy="author", orphanRemoval=true)
72
     */
73
    private $applications;
74
75
    /**
76
     * @ORM\Column(type="string", length=255, nullable=true)
77
     * @Assert\File(mimeTypes={ "image/pdf", "image/jpg", "image/png" })
78
     */
79
    private $curriculum;
80
81
    /**
82
     * @ORM\Column(type="string", length=255, nullable=true)
83
     */
84
    private $Company;
85
86
    /**
87
     * @ORM\Column(type="string", length=255)
88
     */
89
    private $mode;
90
91
    /**
92
     * @ORM\Column(type="string", length=100, nullable=true)
93
     */
94
    private $token;
95
96
    /**
97
     * @ORM\Column(type="boolean")
98
     */
99
    private $validation;
100
101
    public function __construct()
102
    {
103
        $this->adverts = new ArrayCollection();
104
        $this->applications = new ArrayCollection();
105
    }
106
107
    public function getId(): ?int
108
    {
109
        return $this->id;
110
    }
111
112
    public function getEmail(): ?string
113
    {
114
        return $this->email;
115
    }
116
117
    public function setEmail(string $email): self
118
    {
119
        $this->email = $email;
120
121
        return $this;
122
    }
123
124
    /**
125
     * A visual identifier that represents this user.
126
     *
127
     * @see UserInterface
128
     */
129
    public function getUsername(): string
130
    {
131
        return (string) $this->email;
132
    }
133
134
    /**
135
     * @see UserInterface
136
     */
137
    public function getRoles(): array
138
    {
139
        $roles = $this->roles;
140
        // guarantee every user at least has ROLE_USER
141
        $roles[] = 'ROLE_USER';
142
143
        return array_unique($roles);
144
    }
145
146
    public function setRoles(array $roles): self
147
    {
148
        $this->roles = $roles;
149
150
        return $this;
151
    }
152
153
    /**
154
     * @see UserInterface
155
     */
156
    public function getPassword(): string
157
    {
158
        return (string) $this->password;
159
    }
160
161
    public function setPassword(string $password): self
162
    {
163
        $this->password = $password;
164
165
        return $this;
166
    }
167
168
    /**
169
     * @see UserInterface
170
     */
171
    public function getSalt()
172
    {
173
        // not needed when using the "bcrypt" algorithm in security.yaml
174
    }
175
176
    /**
177
     * @see UserInterface
178
     */
179
    public function eraseCredentials()
180
    {
181
        // If you store any temporary, sensitive data on the user, clear it here
182
        // $this->plainPassword = null;
183
    }
184
185
    /**
186
     * @return mixed
187
     */
188
    public function getPlainPassword()
189
    {
190
        return $this->plainPassword;
191
    }
192
193
    /**
194
     * @param mixed $plainPassword
195
     */
196
    public function setPlainPassword($plainPassword): void
197
    {
198
        $this->plainPassword = $plainPassword;
199
    }
200
201
    /**
202
     * @param mixed $username
203
     */
204
    public function setUsername($username): void
205
    {
206
        $this->username = $username;
207
    }
208
209
    /**
210
     * @return Collection|Advert[]
211
     */
212
    public function getAdverts(): Collection
213
    {
214
        return $this->adverts;
215
    }
216
217
    public function addAdvert(Advert $advert): self
218
    {
219
        if (!$this->adverts->contains($advert)) {
220
            $this->adverts[] = $advert;
221
            $advert->setAuthor($this);
222
        }
223
224
        return $this;
225
    }
226
227
    public function removeAdvert(Advert $advert): self
228
    {
229
        if ($this->adverts->contains($advert)) {
230
            $this->adverts->removeElement($advert);
231
            // set the owning side to null (unless already changed)
232
            if ($advert->getAuthor() === $this) {
233
                $advert->setAuthor(null);
234
            }
235
        }
236
237
        return $this;
238
    }
239
240
    /**
241
     * @return Collection|Application[]
242
     */
243
    public function getApplications(): Collection
244
    {
245
        return $this->applications;
246
    }
247
248
    public function addApplication(Application $application): self
249
    {
250
        if (!$this->applications->contains($application)) {
251
            $this->applications[] = $application;
252
            $application->setAuthor($this);
253
        }
254
255
        return $this;
256
    }
257
258
    public function removeApplication(Application $application): self
259
    {
260
        if ($this->applications->contains($application)) {
261
            $this->applications->removeElement($application);
262
            // set the owning side to null (unless already changed)
263
            if ($application->getAuthor() === $this) {
264
                $application->setAuthor(null);
265
            }
266
        }
267
268
        return $this;
269
    }
270
271
    public function getCurriculum(): ?string
272
    {
273
        return $this->curriculum;
274
    }
275
276
    public function setCurriculum(?string $curriculum): self
277
    {
278
        $this->curriculum = $curriculum;
279
280
        return $this;
281
    }
282
283
    public function getCompany(): ?string
284
    {
285
        return $this->Company;
286
    }
287
288
    public function setCompany(?string $Company): self
289
    {
290
        $this->Company = $Company;
291
292
        return $this;
293
    }
294
295
    public function getMode(): ?string
296
    {
297
        return $this->mode;
298
    }
299
300
    public function setMode(string $mode): self
301
    {
302
        $this->mode = $mode;
303
304
        return $this;
305
    }
306
307
    public function getToken(): ?string
308
    {
309
        return $this->token;
310
    }
311
312
    public function setToken(?string $token): self
313
    {
314
        $this->token = $token;
315
316
        return $this;
317
    }
318
319
    public function getValidation(): ?bool
320
    {
321
        return $this->validation;
322
    }
323
324
    public function setValidation(bool $validation): self
325
    {
326
        $this->validation = $validation;
327
328
        return $this;
329
    }
330
}
331