Total Complexity | 11 |
Total Lines | 106 |
Duplicated Lines | 0 % |
Coverage | 40% |
Changes | 0 |
1 | <?php |
||
40 | class User extends BaseModel implements |
||
41 | // Laravel contracts for native login |
||
42 | AuthenticatableContract, |
||
43 | CanResetPasswordContract, |
||
44 | // Contract for use with Gates and Policies |
||
45 | AuthorizableContract |
||
46 | // Custom contract for use with openid login |
||
47 | // \App\Services\Auth\Contracts\OidcAuthenticatable |
||
48 | { |
||
49 | |||
50 | //Traits for Laravel basic authentication |
||
51 | use Authenticatable, CanResetPassword; |
||
52 | // Trait for working with Gates and Policies |
||
53 | use Authorizable; |
||
54 | // Trait for notifications |
||
55 | use Notifiable; |
||
|
|||
56 | // Trait for Backpack |
||
57 | use CrudTrait; |
||
58 | |||
59 | protected $casts = [ |
||
1 ignored issue
–
show
|
|||
60 | 'is_confirmed' => 'boolean', |
||
61 | 'is_priority' => 'boolean', |
||
62 | 'user_role_id' => 'int', |
||
63 | 'email' => 'string', |
||
64 | ]; |
||
65 | protected $fillable = [ |
||
1 ignored issue
–
show
|
|||
66 | 'name', 'email', 'password', 'is_priority' |
||
67 | ]; |
||
68 | protected $with = ['user_role']; |
||
1 ignored issue
–
show
|
|||
69 | protected $hidden = [ |
||
1 ignored issue
–
show
|
|||
70 | 'password', 'remember_token', |
||
71 | ]; |
||
72 | |||
73 | /** |
||
74 | * The event map for the model. |
||
75 | * |
||
76 | * @var array |
||
77 | */ |
||
78 | protected $dispatchesEvents = [ |
||
79 | 'created' => UserCreated::class, |
||
80 | 'updated' => UserUpdated::class, |
||
81 | ]; |
||
82 | |||
83 | 5 | public function applicant() { |
|
1 ignored issue
–
show
|
|||
84 | 5 | return $this->hasOne(\App\Models\Applicant::class); |
|
85 | } |
||
86 | |||
87 | 13 | public function manager() { |
|
1 ignored issue
–
show
|
|||
88 | 13 | return $this->hasOne(\App\Models\Manager::class); |
|
89 | } |
||
90 | |||
91 | public function profile_pic() { |
||
1 ignored issue
–
show
|
|||
92 | return $this->hasOne(\App\Models\ProfilePic::class); |
||
93 | } |
||
94 | |||
95 | 38 | public function user_role() { |
|
1 ignored issue
–
show
|
|||
96 | 38 | return $this->belongsTo(\App\Models\UserRole::class); |
|
97 | } |
||
98 | |||
99 | //Role related functions |
||
100 | |||
101 | /** |
||
102 | * Abort with an HTTP error if user doesn't have correct roles |
||
103 | * @param string|array $roles |
||
1 ignored issue
–
show
|
|||
104 | */ |
||
1 ignored issue
–
show
|
|||
105 | public function authorizeRoles($roles) |
||
106 | { |
||
107 | if (is_array($roles)) { |
||
108 | return $this->hasAnyRole($roles) || |
||
109 | abort(401, 'This action is unauthorized.'); |
||
110 | } |
||
111 | return $this->hasRole($roles) || |
||
112 | abort(401, 'This action is unauthorized.'); |
||
113 | } |
||
114 | |||
115 | /** |
||
116 | * Check multiple roles |
||
117 | * @param array $roles |
||
1 ignored issue
–
show
|
|||
118 | */ |
||
1 ignored issue
–
show
|
|||
119 | public function hasAnyRole($roles) |
||
122 | //return null !== $this->roles()->whereIn(‘name’, $roles)->first(); |
||
123 | } |
||
124 | |||
125 | /** |
||
126 | * Check one role |
||
127 | * @param string $role |
||
1 ignored issue
–
show
|
|||
128 | */ |
||
1 ignored issue
–
show
|
|||
129 | 13 | public function hasRole($role) |
|
132 | //return null !== $this->roles()->where(‘name’, $role)->first(); |
||
133 | } |
||
134 | |||
135 | /** |
||
136 | * OVERRIDE |
||
137 | * Send the password reset notification. |
||
138 | * |
||
139 | * @param string $token |
||
2 ignored issues
–
show
|
|||
140 | * |
||
141 | * @return void |
||
142 | */ |
||
143 | public function sendPasswordResetNotification($token) |
||
1 ignored issue
–
show
|
|||
144 | { |
||
145 | $this->notify(new ResetPasswordNotification($token)); |
||
146 | } |
||
148 |