Total Complexity | 21 |
Total Lines | 186 |
Duplicated Lines | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
42 | class User extends BaseModel implements |
||
43 | // Laravel contracts for native login. |
||
44 | AuthenticatableContract, |
||
45 | CanResetPasswordContract, |
||
46 | // Contract for use with Gates and Policies. |
||
47 | AuthorizableContract |
||
48 | // Custom contract for use with openid login. |
||
49 | // \App\Services\Auth\Contracts\OidcAuthenticatable. |
||
50 | { |
||
51 | |||
52 | // Traits for Laravel basic authentication. |
||
53 | use Authenticatable; |
||
54 | use CanResetPassword; |
||
55 | // Trait for working with Gates and Policies. |
||
56 | use Authorizable; |
||
57 | // Trait for notifications. |
||
58 | use Notifiable; |
||
59 | // Trait for Backpack. |
||
60 | use CrudTrait; |
||
61 | |||
62 | protected $casts = [ |
||
1 ignored issue
–
show
|
|||
63 | 'is_confirmed' => 'boolean', |
||
64 | 'is_priority' => 'boolean', |
||
65 | 'user_role_id' => 'int', |
||
66 | 'email' => 'string', |
||
67 | 'gov_email' => 'string', |
||
68 | 'not_in_gov' => 'boolean', |
||
69 | ]; |
||
70 | |||
71 | protected $fillable = [ |
||
1 ignored issue
–
show
|
|||
72 | 'name', 'email', 'password', 'is_priority', 'gov_email', 'not_in_gov' |
||
73 | ]; |
||
74 | |||
75 | protected $with = ['user_role']; |
||
1 ignored issue
–
show
|
|||
76 | |||
77 | protected $hidden = [ |
||
1 ignored issue
–
show
|
|||
78 | 'password', 'remember_token', |
||
79 | ]; |
||
80 | |||
81 | /** |
||
82 | * The event map for the model. |
||
83 | * |
||
84 | * @var array |
||
85 | */ |
||
86 | protected $dispatchesEvents = [ |
||
87 | 'created' => UserCreated::class, |
||
88 | 'updated' => UserUpdated::class, |
||
89 | ]; |
||
90 | |||
91 | public function applicant() //phpcs:ignore |
||
92 | { |
||
93 | return $this->hasOne(\App\Models\Applicant::class); |
||
94 | } |
||
95 | |||
96 | public function manager() //phpcs:ignore |
||
97 | { |
||
98 | return $this->hasOne(\App\Models\Manager::class); |
||
99 | } |
||
100 | |||
101 | public function profile_pic() //phpcs:ignore |
||
104 | } |
||
105 | |||
106 | public function user_role() //phpcs:ignore |
||
109 | } |
||
110 | |||
111 | public function setIsPriorityAttribute($value) |
||
1 ignored issue
–
show
|
|||
112 | { |
||
113 | if ($value === null) { |
||
114 | $value = false; |
||
115 | } |
||
116 | $this->attributes['is_priority'] = $value; |
||
117 | } |
||
118 | |||
119 | // Role related functions |
||
120 | |||
121 | /** |
||
122 | * Returns true if this user has the Applicant role. |
||
123 | * |
||
124 | * @return boolean |
||
125 | */ |
||
126 | public function isApplicant(): bool |
||
127 | { |
||
128 | // Currently, every user can create an Applicant profile and apply to jobs. |
||
129 | return true; |
||
130 | } |
||
131 | |||
132 | /** |
||
133 | * Returns true if this user has the upgradedManager role. |
||
134 | * |
||
135 | * @return boolean |
||
136 | */ |
||
137 | public function isUpgradedManager(): bool |
||
138 | { |
||
139 | return $this->isAdmin() || $this->user_role->name === 'upgradedManager'; |
||
140 | } |
||
141 | |||
142 | /** |
||
143 | * Returns true this user has the demoManager role. |
||
144 | * |
||
145 | * @return boolean |
||
146 | */ |
||
147 | public function isDemoManager(): bool |
||
148 | { |
||
149 | // Currently, every non-upgradedManager user can be considered a demoManager. |
||
150 | return !$this->isUpgradedManager(); |
||
151 | } |
||
152 | |||
153 | /** |
||
154 | * Returns true if this user has the demoManager or upgradedManager role. |
||
155 | * |
||
156 | * @return boolean |
||
157 | */ |
||
158 | public function isManager(): bool |
||
159 | { |
||
160 | // Currently, every user can use the Manager portal as a demoManager. |
||
161 | return $this->isDemoManager() || $this->isUpgradedManager(); |
||
162 | } |
||
163 | |||
164 | /** |
||
165 | * Returns true if this user has the Admin role. |
||
166 | * |
||
167 | * @return boolean |
||
168 | */ |
||
169 | public function isAdmin(): bool |
||
170 | { |
||
171 | return $this->user_role->name === 'admin'; |
||
172 | } |
||
173 | |||
174 | /** |
||
175 | * Check if the user has the specified role. |
||
176 | * @param string $role This may be either 'applicant', 'manager' or 'admin'. |
||
177 | * @return boolean |
||
178 | */ |
||
179 | public function hasRole($role) |
||
190 | } |
||
191 | } |
||
192 | |||
193 | /** |
||
194 | * Set this user to the specified role. |
||
195 | * |
||
196 | * @param string $role Must be either 'applicant', 'manager' or 'admin. |
||
197 | * @return void |
||
198 | */ |
||
199 | public function setRole(string $role): void |
||
202 | } |
||
203 | |||
204 | /** |
||
205 | * OVERRIDE |
||
206 | * Send the password reset notification. |
||
207 | * |
||
208 | * @param string $token |
||
2 ignored issues
–
show
|
|||
209 | * |
||
210 | * @return void |
||
211 | */ |
||
212 | public function sendPasswordResetNotification($token) |
||
1 ignored issue
–
show
|
|||
213 | { |
||
214 | $this->notify(new ResetPasswordNotification($token)); |
||
215 | } |
||
216 | |||
217 | /** |
||
218 | * Gov identity has been confirmed either if: |
||
219 | * - they have confirmed to NOT be in government, |
||
220 | * - OR they've added a gov email. |
||
221 | * |
||
222 | * @param [type] $user |
||
2 ignored issues
–
show
|
|||
223 | * @return boolean |
||
224 | */ |
||
225 | public function isGovIdentityConfirmed() |
||
230 |