-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathUser.php
More file actions
316 lines (272 loc) · 6.32 KB
/
User.php
File metadata and controls
316 lines (272 loc) · 6.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
<?php
namespace HMS\Entities;
use HMS\Entities\Banking\Account;
use Laravel\Passport\HasApiTokens;
use HMS\Traits\Entities\SoftDeletable;
use HMS\Traits\Entities\Timestampable;
use LaravelDoctrine\ACL\Roles\HasRoles;
use Illuminate\Auth\Passwords\CanResetPassword;
use Doctrine\Common\Collections\ArrayCollection;
use LaravelDoctrine\ORM\Notifications\Notifiable;
use Illuminate\Foundation\Auth\Access\Authorizable;
use LaravelDoctrine\ACL\Permissions\HasPermissions;
use LaravelDoctrine\ACL\Contracts\HasRoles as HasRoleContract;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
use LaravelDoctrine\ACL\Contracts\HasPermissions as HasPermissionsContract;
class User implements AuthenticatableContract, CanResetPasswordContract, HasRoleContract, HasPermissionsContract, AuthorizableContract
{
use CanResetPassword, Notifiable, HasRoles, HasPermissions, SoftDeletable, Timestampable, Authorizable, HasApiTokens;
const MIN_PASSWORD_LENGTH = 3;
/**
* @var int
*/
protected $id;
/**
* @var string Users first name
*/
public $name;
/**
* @var string Users last name
*/
protected $lastname;
/**
* @var string Users username for login
*/
protected $username;
/**
* @var string Users email address
*/
public $email;
/**
* @var string Users remember me token for persisting login sessions
*/
protected $rememberToken;
/**
* @var \Doctrine\Common\Collections\Collection|\LaravelDoctrine\ACL\Contracts\Role[]
*/
protected $roles;
/**
* @var ?Profile The users profile
*/
protected $profile;
/**
* @var ?Account
*/
protected $account;
/**
* @var \Doctrine\Common\Collections\Collection|Email[]
*/
protected $emails;
/**
* User constructor.
* @param string $firstname
* @param string $lastname
* @param string $username
* @param string $email
*/
public function __construct(string $firstname, string $lastname, string $username, string $email)
{
$this->name = $firstname;
$this->lastname = $lastname;
$this->username = $username;
$this->email = $email;
$this->roles = new ArrayCollection();
$this->emails = new ArrayCollection();
}
/**
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* @return string
*/
public function getFirstname(): string
{
return $this->name;
}
/**
* @return string
*/
public function getLastname(): string
{
return $this->lastname;
}
/**
* @return string
*/
public function getFullname(): string
{
return $this->name . ' ' . $this->lastname;
}
/**
* @return string
*/
public function getUsername(): string
{
return $this->username;
}
/**
* @return string
*/
public function getEmail(): string
{
return $this->email;
}
/**
* Get the name of the unique identifier for the user.
*
* @return string
*/
public function getAuthIdentifierName(): string
{
return 'username';
}
/**
* Get the unique identifier for the user.
*
* @return mixed
*/
public function getAuthIdentifier()
{
return $this->{$this->getAuthIdentifierName()};
}
/**
* Get the password for the user.
* @return string
*/
public function getAuthPassword()
{
throw new Exception('Not Supported');
}
/**
* Get the token value for the "remember me" session.
* @return string
*/
public function getRememberToken(): string
{
return $this->{$this->getRememberTokenName()};
}
/**
* Set the token value for the "remember me" session.
*
* @param string $value
*
* @return self
*/
public function setRememberToken($value): User
{
$this->{$this->getRememberTokenName()} = $value;
return $this;
}
/**
* Get the column name for the "remember me" token.
* @return string
*/
public function getRememberTokenName(): string
{
return 'rememberToken';
}
/**
* @return ArrayCollection|Role[]
*/
public function getRoles()
{
return $this->roles;
}
/**
* @return ArrayCollection|Permission[]
*/
public function getPermissions()
{
// user's don't directly have permissions, only via their roles
return [];
}
/**
* @return ?Profile The users profile
*/
public function getProfile() : ?Profile
{
return $this->profile;
}
/**
* @param ?Profile $profile
* @return self
*/
public function setProfile(?Profile $profile): User
{
$this->profile = $profile;
return $this;
}
/**
* @return ?Account The users account
*/
public function getAccount() : ?Account
{
return $this->account;
}
/**
* @param ?Account $account
* @return self
*/
public function setAccount(?Account $account): User
{
$this->account = $account;
return $this;
}
/**
* use by passport.
* @return int
*/
public function getKey()
{
return $this->getAuthIdentifier();
}
/**
* Sets the value of firstname.
*
* @param string $name the name
*
* @return self
*/
public function setFirstname($firstname)
{
$this->name = $firstname;
return $this;
}
/**
* Sets the value of lastname.
*
* @param string $lastname the lastname
*
* @return self
*/
public function setLastname($lastname)
{
$this->lastname = $lastname;
return $this;
}
/**
* Sets the value of email.
*
* @param string $email the email
*
* @return self
*/
public function setEmail($email)
{
$this->email = $email;
return $this;
}
/**
* @return ArrayCollection|Email[]
*/
public function getEmails()
{
return $this->emails;
}
}