1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Modules\Security\Persistence\Doctrine\Entity; |
4
|
|
|
|
5
|
|
|
use Doctrine\ORM\Mapping as ORM; |
6
|
|
|
use Symfony\Bridge\Doctrine\IdGenerator\UlidGenerator; |
7
|
|
|
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface; |
8
|
|
|
use Symfony\Component\Security\Core\User\UserInterface; |
9
|
|
|
use Symfony\Component\Uid\Ulid; |
10
|
|
|
|
11
|
|
|
#[ORM\Entity] |
12
|
|
|
#[ORM\Table(name: "USERS")] |
13
|
|
|
class User implements UserInterface, PasswordAuthenticatedUserInterface |
14
|
|
|
{ |
15
|
|
|
|
16
|
1 |
|
/** |
17
|
|
|
* @var Ulid |
18
|
|
|
*/ |
19
|
|
|
#[ORM\Id] |
20
|
|
|
#[ORM\GeneratedValue(strategy: "CUSTOM")] |
21
|
|
|
#[ORM\CustomIdGenerator(class: UlidGenerator::class)] |
22
|
|
|
#[ORM\Column(type: "ulid", unique: true)] |
23
|
|
|
private Ulid $id; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
#[ORM\Column(type: "string", length: 180, unique: true)] |
29
|
|
|
private string $email; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var array<string> |
33
|
|
|
*/ |
34
|
|
|
#[ORM\Column(type: "json")] |
35
|
|
|
private array $roles = []; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var string The hashed password |
39
|
|
|
*/ |
40
|
|
|
#[ORM\Column(type: "string")] |
41
|
|
|
private string $password; |
42
|
|
|
|
43
|
|
|
#[ORM\Version] |
44
|
|
|
#[ORM\Column(type: "integer")] |
45
|
|
|
private $version; |
46
|
|
|
|
47
|
|
|
|
48
|
|
|
public function getId(): ?Ulid |
49
|
|
|
{ |
50
|
|
|
return $this->id; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function getEmail(): ?string |
54
|
3 |
|
{ |
55
|
|
|
return $this->email; |
56
|
3 |
|
} |
57
|
|
|
|
58
|
|
|
public function setEmail(string $email): self |
59
|
3 |
|
{ |
60
|
|
|
$this->email = $email; |
61
|
3 |
|
|
62
|
|
|
return $this; |
63
|
|
|
} |
64
|
1 |
|
|
65
|
|
|
/** |
66
|
1 |
|
* The public representation of the user (e.g. a username, an email address, etc.) |
67
|
|
|
* |
68
|
1 |
|
* @see UserInterface |
69
|
|
|
*/ |
70
|
|
|
public function getUserIdentifier(): string |
71
|
|
|
{ |
72
|
|
|
return (string)$this->email; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
3 |
|
* @see UserInterface |
77
|
|
|
*/ |
78
|
3 |
|
public function getRoles(): array |
79
|
|
|
{ |
80
|
|
|
$roles = $this->roles; |
81
|
|
|
// guarantee every user at least has ROLE_USER |
82
|
|
|
$roles[] = 'ROLE_USER'; |
83
|
|
|
|
84
|
3 |
|
return array_unique($roles); |
85
|
|
|
} |
86
|
3 |
|
|
87
|
|
|
public function setRoles(array $roles): self |
88
|
3 |
|
{ |
89
|
|
|
$this->roles = $roles; |
90
|
3 |
|
|
91
|
|
|
return $this; |
92
|
|
|
} |
93
|
1 |
|
|
94
|
|
|
/** |
95
|
1 |
|
* @see PasswordAuthenticatedUserInterface |
96
|
|
|
*/ |
97
|
1 |
|
public function getPassword(): string |
98
|
|
|
{ |
99
|
|
|
return $this->password; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
public function setPassword(string $password): self |
103
|
3 |
|
{ |
104
|
|
|
$this->password = $password; |
105
|
3 |
|
|
106
|
|
|
return $this; |
107
|
|
|
} |
108
|
1 |
|
|
109
|
|
|
/** |
110
|
1 |
|
* Returning a salt is only needed, if you are not using a modern |
111
|
|
|
* hashing algorithm (e.g. bcrypt or sodium) in your security.yaml. |
112
|
1 |
|
* |
113
|
|
|
* @see UserInterface |
114
|
|
|
*/ |
115
|
|
|
public function getSalt(): ?string |
116
|
|
|
{ |
117
|
|
|
return null; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @see UserInterface |
122
|
|
|
*/ |
123
|
|
|
public function eraseCredentials() |
124
|
|
|
{ |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* @return mixed |
129
|
3 |
|
*/ |
130
|
|
|
public function getVersion() |
131
|
|
|
{ |
132
|
|
|
return $this->version; |
133
|
3 |
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* @param mixed $version |
137
|
|
|
*/ |
138
|
|
|
public function setVersion($version): void |
139
|
|
|
{ |
140
|
|
|
$this->version = $version; |
141
|
|
|
} |
142
|
|
|
} |