|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of the zibios/sharep. |
|
7
|
|
|
* |
|
8
|
|
|
* (c) Zbigniew Ślązak |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace App\Entity\Access; |
|
12
|
|
|
|
|
13
|
|
|
use App\Entity\EntityInterface; |
|
14
|
|
|
use App\Entity\Parking\Member; |
|
15
|
|
|
use App\Entity\Traits; |
|
16
|
|
|
use Doctrine\ORM\Mapping as ORM; |
|
17
|
|
|
use PascalDeVink\ShortUuid\ShortUuid; |
|
18
|
|
|
use Symfony\Bridge\Doctrine\Validator\Constraints as OrmAssert; |
|
19
|
|
|
use Symfony\Component\Security\Core\User\UserInterface; |
|
20
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @ORM\Entity(repositoryClass="App\Repository\Entity\Account\UserRepository") |
|
24
|
|
|
* @ORM\Table(name="access_users") |
|
25
|
|
|
* @OrmAssert\UniqueEntity(fields={"email"}, errorPath="email", message="Email already exist") |
|
26
|
|
|
* @OrmAssert\UniqueEntity(fields={"member"}, errorPath="member", message="Member already exist") |
|
27
|
|
|
*/ |
|
28
|
|
|
class User implements UserInterface, EntityInterface |
|
29
|
|
|
{ |
|
30
|
|
|
use Traits\PropertyIdGeneratedTrait; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var string|null |
|
34
|
|
|
* @ORM\Column(name="email", type="string", length=255, nullable=false, unique=true) |
|
35
|
|
|
* |
|
36
|
|
|
* @Assert\NotBlank() |
|
37
|
|
|
* @Assert\Email() |
|
38
|
|
|
* @Assert\Length(min="1", max="255") |
|
39
|
|
|
*/ |
|
40
|
|
|
private $email; |
|
41
|
|
|
|
|
42
|
|
|
//------------------------------------------------------------------------------------------- |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @var GoogleIdentity|null |
|
46
|
|
|
* @ORM\OneToOne(targetEntity="App\Entity\Access\GoogleIdentity", mappedBy="user", cascade={"persist"}) |
|
47
|
|
|
*/ |
|
48
|
|
|
private $googleIdentity; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @var SlackIdentity|null |
|
52
|
|
|
* @ORM\OneToOne(targetEntity="App\Entity\Access\SlackIdentity", mappedBy="user", cascade={"persist"}) |
|
53
|
|
|
*/ |
|
54
|
|
|
private $slackIdentity; |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @var Member|null |
|
58
|
|
|
* @ORM\OneToOne(targetEntity="App\Entity\Parking\Member", mappedBy="user", cascade={"persist"}) |
|
59
|
|
|
*/ |
|
60
|
|
|
private $member; |
|
61
|
|
|
|
|
62
|
|
|
//------------------------------------------------------------------------------------------- |
|
63
|
|
|
|
|
64
|
14 |
|
public function __construct() |
|
65
|
|
|
{ |
|
66
|
14 |
|
$this->id = ShortUuid::uuid4(); |
|
67
|
14 |
|
} |
|
68
|
|
|
|
|
69
|
|
|
//------------------------------------------------------------------------------------------- |
|
70
|
|
|
|
|
71
|
17 |
|
public function getEmail(): ?string |
|
72
|
|
|
{ |
|
73
|
17 |
|
return $this->email; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
13 |
|
public function setEmail(string $email): self |
|
77
|
|
|
{ |
|
78
|
13 |
|
$this->email = trim($email); |
|
79
|
|
|
|
|
80
|
13 |
|
return $this; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
//------------------------------------------------------------------------------------------- |
|
84
|
|
|
|
|
85
|
|
|
public function getGoogleIdentity(): ?GoogleIdentity |
|
86
|
|
|
{ |
|
87
|
|
|
return $this->googleIdentity; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
public function setGoogleIdentity(GoogleIdentity $googleIdentity): self |
|
91
|
|
|
{ |
|
92
|
|
|
$this->googleIdentity = $googleIdentity; |
|
93
|
|
|
|
|
94
|
|
|
return $this; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
3 |
|
public function getSlackIdentity(): ?SlackIdentity |
|
98
|
|
|
{ |
|
99
|
3 |
|
return $this->slackIdentity; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
public function setSlackIdentity(?GoogleIdentity $slackIdentity): self |
|
103
|
|
|
{ |
|
104
|
|
|
$this->slackIdentity = $slackIdentity; |
|
105
|
|
|
|
|
106
|
|
|
return $this; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
16 |
|
public function getMember(): ?Member |
|
110
|
|
|
{ |
|
111
|
16 |
|
return $this->member; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
public function setMember(Member $member): self |
|
115
|
|
|
{ |
|
116
|
|
|
$this->member = $member; |
|
117
|
|
|
|
|
118
|
|
|
return $this; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
//------------------------------------------------------------------------------------------- |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* Returns the roles granted to the user. |
|
125
|
|
|
* |
|
126
|
|
|
* <code> |
|
127
|
|
|
* public function getRoles() |
|
128
|
|
|
* { |
|
129
|
|
|
* return array('ROLE_USER'); |
|
130
|
|
|
* } |
|
131
|
|
|
* </code> |
|
132
|
|
|
* |
|
133
|
|
|
* Alternatively, the roles might be stored on a ``roles`` property, |
|
134
|
|
|
* and populated in any number of different ways when the user object |
|
135
|
|
|
* is created. |
|
136
|
|
|
* |
|
137
|
|
|
* @return string[] The user roles |
|
138
|
|
|
*/ |
|
139
|
17 |
|
public function getRoles(): array |
|
140
|
|
|
{ |
|
141
|
17 |
|
return ['ROLE_USER']; |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
/** |
|
145
|
|
|
* Returns the password used to authenticate the user. |
|
146
|
|
|
* |
|
147
|
|
|
* This should be the encoded password. On authentication, a plain-text |
|
148
|
|
|
* password will be salted, encoded, and then compared to this value. |
|
149
|
|
|
* |
|
150
|
|
|
* @return string The password |
|
|
|
|
|
|
151
|
|
|
*/ |
|
152
|
17 |
|
public function getPassword(): ?string |
|
153
|
|
|
{ |
|
154
|
17 |
|
return null; |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
/** |
|
158
|
|
|
* Returns the salt that was originally used to encode the password. |
|
159
|
|
|
* |
|
160
|
|
|
* This can return null if the password was not encoded using a salt. |
|
161
|
|
|
* |
|
162
|
|
|
* @return string|null The salt |
|
163
|
|
|
*/ |
|
164
|
17 |
|
public function getSalt(): ?string |
|
165
|
|
|
{ |
|
166
|
17 |
|
return null; |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
/** |
|
170
|
|
|
* Returns the username used to authenticate the user. |
|
171
|
|
|
* |
|
172
|
|
|
* @return string The username |
|
|
|
|
|
|
173
|
|
|
*/ |
|
174
|
17 |
|
public function getUsername(): ?string |
|
175
|
|
|
{ |
|
176
|
17 |
|
return $this->getEmail(); |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
/** |
|
180
|
|
|
* Removes sensitive data from the user. |
|
181
|
|
|
* |
|
182
|
|
|
* This is important if, at any given point, sensitive information like |
|
183
|
|
|
* the plain-text password is stored on this object. |
|
184
|
|
|
*/ |
|
185
|
|
|
public function eraseCredentials(): void |
|
186
|
|
|
{ |
|
187
|
|
|
} |
|
188
|
|
|
} |
|
189
|
|
|
|
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.