1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Document; |
4
|
|
|
|
5
|
|
|
use Doctrine\Bundle\MongoDBBundle\Validator\Constraints\Unique as MongoDBUnique; |
6
|
|
|
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB; |
7
|
|
|
use Symfony\Component\Serializer\Annotation\Groups; |
8
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @MongoDB\Document(repositoryClass="App\Repositories\UserRepository") |
12
|
|
|
* @MongoDBUnique(fields="username") |
13
|
|
|
* @MongoDBUnique(fields="email") |
14
|
|
|
*/ |
15
|
|
|
class User extends AbstractUser |
16
|
|
|
{ |
17
|
|
|
const TYPE_INTERNAL = 'internal'; |
18
|
|
|
const TYPE_GITLAB = 'gitlab'; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @MongoDB\Field(type="string") |
22
|
|
|
* @MongoDB\Index() |
23
|
|
|
* |
24
|
|
|
* @Groups({"user_profile", "user_write", "user_default", "user_full", "user_autocomplete"}) |
25
|
|
|
* @Assert\NotBlank |
26
|
|
|
*/ |
27
|
|
|
protected $username; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @MongoDB\Field(type="string") |
31
|
|
|
* |
32
|
|
|
* @Groups({"user_profile", "user_write", "user_default", "user_full", "user_autocomplete"}) |
33
|
|
|
* @Assert\NotBlank |
34
|
|
|
* @Assert\Email |
35
|
|
|
*/ |
36
|
|
|
protected $email; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @MongoDB\Field(type="string") |
40
|
|
|
* |
41
|
|
|
* @Groups({"user_profile", "user_write", "user_default", "user_full", "user_autocomplete"}) |
42
|
|
|
* @Assert\NotBlank |
43
|
|
|
*/ |
44
|
|
|
protected $fullName; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @MongoDB\Field(type="string") |
48
|
|
|
* |
49
|
|
|
* @Groups({"user_profile", "user_default", "user_full", "user_autocomplete"}) |
50
|
|
|
*/ |
51
|
|
|
protected $avatarUrl; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @MongoDB\Field(type="string") |
55
|
|
|
* @Groups({"user_default", "user_full"}) |
56
|
|
|
* @Assert\Choice({User::TYPE_INTERNAL, User::TYPE_GITLAB}) |
57
|
|
|
* @Assert\NotBlank |
58
|
|
|
*/ |
59
|
|
|
protected $type; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @Assert\Length(min=8, groups={"password"}) |
63
|
|
|
* @Assert\Regex( |
64
|
|
|
* "/^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9]|.*[\?!:$@&_#\*\-\+]).*$/", groups={"password"}, |
65
|
|
|
* message="Your password must be have at least 8 characters, 1 uppercase & 1 lowercase character, 1 number and 1 special character." |
66
|
|
|
* ) |
67
|
|
|
* @Assert\NotBlank(groups={"password"}) |
68
|
|
|
*/ |
69
|
|
|
protected $plainPassword; |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @MongoDB\Field(type="string") |
73
|
|
|
*/ |
74
|
|
|
protected $password; |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @MongoDB\Field(type="string") |
78
|
|
|
*/ |
79
|
|
|
protected $resetPasswordToken; |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @MongoDB\Field(type="string") |
83
|
|
|
* @Groups({"user_write", "user_default", "user_full", "user_profile"}) |
84
|
|
|
* @Assert\Choice({User::ROLE_ADMIN, User::ROLE_MANAGER, User::ROLE_USER}) |
85
|
|
|
* @Assert\NotBlank |
86
|
|
|
*/ |
87
|
|
|
protected $role; |
88
|
|
|
|
89
|
|
|
public function __construct() |
90
|
|
|
{ |
91
|
|
|
$this->role = self::ROLE_USER; |
92
|
|
|
$this->type = self::TYPE_INTERNAL; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @Groups({"user_profile"}) |
97
|
|
|
*/ |
98
|
|
|
public function getRoles() |
99
|
|
|
{ |
100
|
|
|
$roles = [$this->getRole()]; |
101
|
|
|
|
102
|
|
|
if (in_array(self::ROLE_ADMIN, $roles)) { |
103
|
|
|
$roles[] = self::ROLE_MANAGER; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
if (in_array(self::ROLE_MANAGER, $roles)) { |
107
|
|
|
$roles[] = self::ROLE_USER; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
return $roles; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
public function getUsername(): string |
114
|
|
|
{ |
115
|
|
|
return $this->username; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
public function setUsername(string $username): self |
119
|
|
|
{ |
120
|
|
|
$this->username = $username; |
121
|
|
|
|
122
|
|
|
return $this; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
public function getEmail(): ?string |
126
|
|
|
{ |
127
|
|
|
return $this->email; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
public function setEmail(string $email): self |
131
|
|
|
{ |
132
|
|
|
$this->email = $email; |
133
|
|
|
|
134
|
|
|
return $this; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
public function getFullName(): ?string |
138
|
|
|
{ |
139
|
|
|
return $this->fullName; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
public function setFullName(string $fullName): self |
143
|
|
|
{ |
144
|
|
|
$this->fullName = $fullName; |
145
|
|
|
|
146
|
|
|
return $this; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
public function getAvatarUrl(): ?string |
150
|
|
|
{ |
151
|
|
|
return $this->avatarUrl; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
public function setAvatarUrl(?string $avatarUrl): self |
155
|
|
|
{ |
156
|
|
|
$this->avatarUrl = $avatarUrl; |
157
|
|
|
|
158
|
|
|
return $this; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
public function getType(): ?string |
162
|
|
|
{ |
163
|
|
|
return $this->type; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
public function setType(string $type): self |
167
|
|
|
{ |
168
|
|
|
$this->type = $type; |
169
|
|
|
|
170
|
|
|
return $this; |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
public function getPlainPassword(): ?string |
174
|
|
|
{ |
175
|
|
|
return $this->plainPassword; |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
public function setPlainPassword(string $plainPassword): self |
179
|
|
|
{ |
180
|
|
|
$this->plainPassword = $plainPassword; |
181
|
|
|
|
182
|
|
|
return $this; |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
public function getPassword(): ?string |
186
|
|
|
{ |
187
|
|
|
return $this->password; |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
public function setPassword(string $password): self |
191
|
|
|
{ |
192
|
|
|
$this->password = $password; |
193
|
|
|
|
194
|
|
|
return $this; |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
public function getResetPasswordToken(): ?string |
198
|
|
|
{ |
199
|
|
|
return $this->resetPasswordToken; |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
public function setResetPasswordToken(string $resetPasswordToken): self |
203
|
|
|
{ |
204
|
|
|
$this->resetPasswordToken = $resetPasswordToken; |
205
|
|
|
|
206
|
|
|
return $this; |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
public function getRole(): ?string |
210
|
|
|
{ |
211
|
|
|
return $this->role; |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
public function setRole(string $role): self |
215
|
|
|
{ |
216
|
|
|
$this->role = $role; |
217
|
|
|
|
218
|
|
|
return $this; |
219
|
|
|
} |
220
|
|
|
} |
221
|
|
|
|