|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* NOTICE OF LICENSE |
|
5
|
|
|
* |
|
6
|
|
|
* Part of the Rinvex Fort Package. |
|
7
|
|
|
* |
|
8
|
|
|
* This source file is subject to The MIT License (MIT) |
|
9
|
|
|
* that is bundled with this package in the LICENSE file. |
|
10
|
|
|
* |
|
11
|
|
|
* Package: Rinvex Fort Package |
|
12
|
|
|
* License: The MIT License (MIT) |
|
13
|
|
|
* Link: https://rinvex.com |
|
14
|
|
|
*/ |
|
15
|
|
|
|
|
16
|
|
|
namespace Rinvex\Fort\Models; |
|
17
|
|
|
|
|
18
|
|
|
use Rinvex\Fort\Traits\CanVerifyEmail; |
|
19
|
|
|
use Rinvex\Fort\Traits\Authenticatable; |
|
20
|
|
|
use Illuminate\Database\Eloquent\Model; |
|
21
|
|
|
use Illuminate\Notifications\Notifiable; |
|
22
|
|
|
use Rinvex\Fort\Traits\CanResetPassword; |
|
23
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes; |
|
24
|
|
|
use Rinvex\Fort\Contracts\CanVerifyEmailContract; |
|
25
|
|
|
use Rinvex\Fort\Contracts\AuthenticatableContract; |
|
26
|
|
|
use Illuminate\Foundation\Auth\Access\Authorizable; |
|
27
|
|
|
use Rinvex\Fort\Contracts\CanResetPasswordContract; |
|
28
|
|
|
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract; |
|
29
|
|
|
|
|
30
|
|
|
class User extends Model implements AuthenticatableContract, AuthorizableContract, CanResetPasswordContract, CanVerifyEmailContract |
|
|
|
|
|
|
31
|
|
|
{ |
|
32
|
|
|
use Notifiable, Authenticatable, Authorizable, CanResetPassword, CanVerifyEmail, SoftDeletes; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* {@inheritdoc} |
|
36
|
|
|
*/ |
|
37
|
|
|
protected $dates = [ |
|
38
|
|
|
'email_verified_at', |
|
39
|
|
|
'deleted_at', |
|
40
|
|
|
'birthdate', |
|
41
|
|
|
'login_at', |
|
42
|
|
|
]; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* {@inheritdoc} |
|
46
|
|
|
*/ |
|
47
|
|
|
protected $fillable = [ |
|
48
|
|
|
'username', |
|
49
|
|
|
'password', |
|
50
|
|
|
'two_factor', |
|
51
|
|
|
'email', |
|
52
|
|
|
'email_verified', |
|
53
|
|
|
'email_verified_at', |
|
54
|
|
|
'phone', |
|
55
|
|
|
'phone_verified', |
|
56
|
|
|
'phone_verified_at', |
|
57
|
|
|
'prefix', |
|
58
|
|
|
'first_name', |
|
59
|
|
|
'middle_name', |
|
60
|
|
|
'last_name', |
|
61
|
|
|
'sufix', |
|
62
|
|
|
'job_title', |
|
63
|
|
|
'country', |
|
64
|
|
|
'birthdate', |
|
65
|
|
|
'gender', |
|
66
|
|
|
'moderated', |
|
67
|
|
|
'login_at', |
|
68
|
|
|
]; |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* {@inheritdoc} |
|
72
|
|
|
*/ |
|
73
|
|
|
protected $hidden = [ |
|
74
|
|
|
'password', |
|
75
|
|
|
'two_factor', |
|
76
|
|
|
'remember_token', |
|
77
|
|
|
]; |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* {@inheritdoc} |
|
81
|
|
|
*/ |
|
82
|
|
|
protected $with = ['abilities', 'roles']; |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* Create a new Eloquent model instance. |
|
86
|
|
|
* |
|
87
|
|
|
* @param array $attributes |
|
88
|
|
|
* |
|
89
|
|
|
* @return void |
|
|
|
|
|
|
90
|
|
|
*/ |
|
91
|
|
|
public function __construct(array $attributes = []) |
|
92
|
|
|
{ |
|
93
|
|
|
parent::__construct($attributes); |
|
94
|
|
|
|
|
95
|
|
|
$this->setTable(config('rinvex.fort.tables.users')); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* A user may have multiple direct abilities. |
|
100
|
|
|
* |
|
101
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany |
|
102
|
|
|
*/ |
|
103
|
|
|
public function abilities() |
|
104
|
|
|
{ |
|
105
|
|
|
return $this->belongsToMany(config('rinvex.fort.models.ability'), config('rinvex.fort.tables.ability_user')) |
|
106
|
|
|
->withTimestamps(); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* A user may have multiple roles. |
|
111
|
|
|
* |
|
112
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany |
|
113
|
|
|
*/ |
|
114
|
|
|
public function roles() |
|
115
|
|
|
{ |
|
116
|
|
|
return $this->belongsToMany(config('rinvex.fort.models.role'), config('rinvex.fort.tables.role_user')) |
|
117
|
|
|
->withTimestamps(); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* A user may have multiple persistences. |
|
122
|
|
|
* |
|
123
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany |
|
124
|
|
|
*/ |
|
125
|
|
|
public function persistences() |
|
126
|
|
|
{ |
|
127
|
|
|
return $this->hasMany(config('rinvex.fort.models.persistence')); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* A user may have multiple socialites. |
|
132
|
|
|
* |
|
133
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany |
|
134
|
|
|
*/ |
|
135
|
|
|
public function socialites() |
|
136
|
|
|
{ |
|
137
|
|
|
return $this->hasMany(config('rinvex.fort.models.socialite')); |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* Get all abilities of the user. |
|
142
|
|
|
* |
|
143
|
|
|
* @return \Illuminate\Support\Collection |
|
144
|
|
|
*/ |
|
145
|
|
|
public function getAllAbilitiesAttribute() |
|
146
|
|
|
{ |
|
147
|
|
|
return $this->abilities->merge($this->roles->pluck('abilities')->collapse()); |
|
|
|
|
|
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
/** |
|
151
|
|
|
* Determine if the user is super admin. |
|
152
|
|
|
* |
|
153
|
|
|
* @return bool |
|
154
|
|
|
*/ |
|
155
|
|
|
public function isSuperadmin() |
|
156
|
|
|
{ |
|
157
|
|
|
return $this->getAllAbilitiesAttribute()->where('policy', null)->contains('action', 'superadmin'); |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
/** |
|
161
|
|
|
* Determine if the user is protected. |
|
162
|
|
|
* |
|
163
|
|
|
* @return bool |
|
164
|
|
|
*/ |
|
165
|
|
|
public function isProtected() |
|
166
|
|
|
{ |
|
167
|
|
|
return in_array($this->id, config('rinvex.fort.protected.users')); |
|
|
|
|
|
|
168
|
|
|
} |
|
169
|
|
|
} |
|
170
|
|
|
|
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.