|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Models\Auth\Traits\Attribute; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Support\Facades\Hash; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Trait UserAttribute. |
|
9
|
|
|
*/ |
|
10
|
|
|
trait UserAttribute |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @param $password |
|
14
|
|
|
*/ |
|
15
|
|
|
public function setPasswordAttribute($password) : void |
|
16
|
|
|
{ |
|
17
|
|
|
// If password was accidentally passed in already hashed, try not to double hash it |
|
18
|
|
|
if ( |
|
19
|
|
|
(\strlen($password) === 60 && preg_match('/^\$2y\$/', $password)) || |
|
20
|
|
|
(\strlen($password) === 95 && preg_match('/^\$argon2i\$/', $password)) |
|
21
|
|
|
) { |
|
22
|
|
|
$hash = $password; |
|
23
|
|
|
} else { |
|
24
|
|
|
$hash = Hash::make($password); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
// Note: Password Histories are logged from the \App\Observer\User\UserObserver class |
|
28
|
|
|
$this->attributes['password'] = $hash; |
|
|
|
|
|
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @return string |
|
33
|
|
|
*/ |
|
34
|
|
|
public function getStatusLabelAttribute() |
|
35
|
|
|
{ |
|
36
|
|
|
if ($this->isActive()) { |
|
|
|
|
|
|
37
|
|
|
return "<span class='badge badge-success'>".__('labels.general.active').'</span>'; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
return "<span class='badge badge-danger'>".__('labels.general.inactive').'</span>'; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @return string |
|
45
|
|
|
*/ |
|
46
|
|
|
public function getConfirmedLabelAttribute() |
|
47
|
|
|
{ |
|
48
|
|
|
if ($this->isConfirmed()) { |
|
|
|
|
|
|
49
|
|
|
if ($this->id != 1 && $this->id != auth()->id()) { |
|
50
|
|
|
return '<a href="'.route( |
|
51
|
|
|
'admin.auth.user.unconfirm', |
|
52
|
|
|
$this |
|
53
|
|
|
).'" data-toggle="tooltip" data-placement="top" title="'.__('buttons.backend.access.users.unconfirm').'" name="confirm_item"><span class="badge badge-success" style="cursor:pointer">'.__('labels.general.yes').'</span></a>'; |
|
54
|
|
|
} else { |
|
55
|
|
|
return '<span class="badge badge-success">'.__('labels.general.yes').'</span>'; |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
return '<a href="'.route('admin.auth.user.confirm', $this).'" data-toggle="tooltip" data-placement="top" title="'.__('buttons.backend.access.users.confirm').'" name="confirm_item"><span class="badge badge-danger" style="cursor:pointer">'.__('labels.general.no').'</span></a>'; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @return string |
|
64
|
|
|
*/ |
|
65
|
|
|
public function getFullNameAttribute() |
|
66
|
|
|
{ |
|
67
|
|
|
return $this->last_name |
|
68
|
|
|
? $this->first_name.' '.$this->last_name |
|
69
|
|
|
: $this->first_name; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @return string |
|
74
|
|
|
*/ |
|
75
|
|
|
public function getNameAttribute() |
|
76
|
|
|
{ |
|
77
|
|
|
return $this->full_name; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @return mixed |
|
82
|
|
|
*/ |
|
83
|
|
|
public function getPictureAttribute() |
|
84
|
|
|
{ |
|
85
|
|
|
return $this->getPicture(); |
|
|
|
|
|
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @return string |
|
90
|
|
|
*/ |
|
91
|
|
|
public function getSocialButtonsAttribute() |
|
92
|
|
|
{ |
|
93
|
|
|
$accounts = []; |
|
94
|
|
|
|
|
95
|
|
|
foreach ($this->providers as $social) { |
|
96
|
|
|
$accounts[] = '<a href="'.route( |
|
97
|
|
|
'admin.auth.user.social.unlink', |
|
98
|
|
|
[$this, $social] |
|
99
|
|
|
).'" data-toggle="tooltip" data-placement="top" title="'.__('buttons.backend.access.users.unlink').'" data-method="delete"><i class="fab fa-'.$social->provider.'"></i></a>'; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
return \count($accounts) ? implode(' ', $accounts) : __('labels.general.none'); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* @return string |
|
107
|
|
|
*/ |
|
108
|
|
|
public function getLoginAsButtonAttribute() |
|
109
|
|
|
{ |
|
110
|
|
|
/* |
|
111
|
|
|
* If the admin is currently NOT spoofing a user |
|
112
|
|
|
*/ |
|
113
|
|
|
if (! session()->has('admin_user_id') || ! session()->has('temp_user_id')) { |
|
114
|
|
|
//Won't break, but don't let them "Login As" themselves |
|
115
|
|
|
if ($this->id != auth()->id()) { |
|
116
|
|
|
return '<a href="'.route( |
|
117
|
|
|
'admin.auth.user.login-as', |
|
118
|
|
|
$this |
|
119
|
|
|
).'" class="dropdown-item">'.__('buttons.backend.access.users.login_as', ['user' => e($this->full_name)]).'</a> '; |
|
|
|
|
|
|
120
|
|
|
} |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
return ''; |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* @return string |
|
128
|
|
|
*/ |
|
129
|
|
|
public function getClearSessionButtonAttribute() |
|
130
|
|
|
{ |
|
131
|
|
|
if ($this->id != auth()->id() && config('session.driver') == 'database') { |
|
132
|
|
|
return '<a href="'.route('admin.auth.user.clear-session', $this).'" |
|
133
|
|
|
data-trans-button-cancel="'.__('buttons.general.cancel').'" |
|
134
|
|
|
data-trans-button-confirm="'.__('buttons.general.continue').'" |
|
135
|
|
|
data-trans-title="'.__('strings.backend.general.are_you_sure').'" |
|
136
|
|
|
class="dropdown-item" name="confirm_item">'.__('buttons.backend.access.users.clear_session').'</a> '; |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
return ''; |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* @return string |
|
144
|
|
|
*/ |
|
145
|
|
|
public function getShowButtonAttribute() |
|
146
|
|
|
{ |
|
147
|
|
|
return '<a href="'.route('admin.auth.user.show', $this).'" data-toggle="tooltip" data-placement="top" title="'.__('buttons.general.crud.view').'" class="btn btn-info"><i class="fas fa-eye"></i></a>'; |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
/** |
|
151
|
|
|
* @return string |
|
152
|
|
|
*/ |
|
153
|
|
|
public function getEditButtonAttribute() |
|
154
|
|
|
{ |
|
155
|
|
|
return '<a href="'.route('admin.auth.user.edit', $this).'" data-toggle="tooltip" data-placement="top" title="'.__('buttons.general.crud.edit').'" class="btn btn-primary"><i class="fas fa-edit"></i></a>'; |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
/** |
|
159
|
|
|
* @return string |
|
160
|
|
|
*/ |
|
161
|
|
|
public function getChangePasswordButtonAttribute() |
|
162
|
|
|
{ |
|
163
|
|
|
return '<a href="'.route('admin.auth.user.change-password', $this).'" class="dropdown-item">'.__('buttons.backend.access.users.change_password').'</a> '; |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
/** |
|
167
|
|
|
* @return string |
|
168
|
|
|
*/ |
|
169
|
|
|
public function getStatusButtonAttribute() |
|
170
|
|
|
{ |
|
171
|
|
|
if ($this->id != auth()->id()) { |
|
172
|
|
|
switch ($this->active) { |
|
173
|
|
|
case 0: |
|
174
|
|
|
return '<a href="'.route('admin.auth.user.mark', [ |
|
175
|
|
|
$this, |
|
176
|
|
|
1, |
|
177
|
|
|
]).'" class="dropdown-item">'.__('buttons.backend.access.users.activate').'</a> '; |
|
178
|
|
|
|
|
179
|
|
|
case 1: |
|
180
|
|
|
return '<a href="'.route('admin.auth.user.mark', [ |
|
181
|
|
|
$this, |
|
182
|
|
|
0, |
|
183
|
|
|
]).'" class="dropdown-item">'.__('buttons.backend.access.users.deactivate').'</a> '; |
|
184
|
|
|
|
|
185
|
|
|
default: |
|
186
|
|
|
return ''; |
|
187
|
|
|
} |
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
|
|
return ''; |
|
191
|
|
|
} |
|
192
|
|
|
|
|
193
|
|
|
/** |
|
194
|
|
|
* @return string |
|
195
|
|
|
*/ |
|
196
|
|
|
public function getConfirmedButtonAttribute() |
|
197
|
|
|
{ |
|
198
|
|
|
if (! $this->isConfirmed() && ! config('access.users.requires_approval')) { |
|
199
|
|
|
return '<a href="'.route('admin.auth.user.account.confirm.resend', $this).'" class="dropdown-item">'.__('buttons.backend.access.users.resend_email').'</a> '; |
|
200
|
|
|
} |
|
201
|
|
|
|
|
202
|
|
|
return ''; |
|
203
|
|
|
} |
|
204
|
|
|
|
|
205
|
|
|
/** |
|
206
|
|
|
* @return string |
|
207
|
|
|
*/ |
|
208
|
|
|
public function getDeleteButtonAttribute() |
|
209
|
|
|
{ |
|
210
|
|
|
if ($this->id != auth()->id() && $this->id != 1) { |
|
211
|
|
|
return '<a href="'.route('admin.auth.user.destroy', $this).'" |
|
212
|
|
|
data-method="delete" |
|
213
|
|
|
data-trans-button-cancel="'.__('buttons.general.cancel').'" |
|
214
|
|
|
data-trans-button-confirm="'.__('buttons.general.crud.delete').'" |
|
215
|
|
|
data-trans-title="'.__('strings.backend.general.are_you_sure').'" |
|
216
|
|
|
class="dropdown-item">'.__('buttons.general.crud.delete').'</a> '; |
|
217
|
|
|
} |
|
218
|
|
|
|
|
219
|
|
|
return ''; |
|
220
|
|
|
} |
|
221
|
|
|
|
|
222
|
|
|
/** |
|
223
|
|
|
* @return string |
|
224
|
|
|
*/ |
|
225
|
|
|
public function getDeletePermanentlyButtonAttribute() |
|
226
|
|
|
{ |
|
227
|
|
|
return '<a href="'.route('admin.auth.user.delete-permanently', $this).'" name="confirm_item" class="btn btn-danger"><i class="fas fa-trash" data-toggle="tooltip" data-placement="top" title="'.__('buttons.backend.access.users.delete_permanently').'"></i></a> '; |
|
228
|
|
|
} |
|
229
|
|
|
|
|
230
|
|
|
/** |
|
231
|
|
|
* @return string |
|
232
|
|
|
*/ |
|
233
|
|
|
public function getRestoreButtonAttribute() |
|
234
|
|
|
{ |
|
235
|
|
|
return '<a href="'.route('admin.auth.user.restore', $this).'" name="confirm_item" class="btn btn-info"><i class="fas fa-refresh" data-toggle="tooltip" data-placement="top" title="'.__('buttons.backend.access.users.restore_user').'"></i></a> '; |
|
236
|
|
|
} |
|
237
|
|
|
|
|
238
|
|
|
/** |
|
239
|
|
|
* @return string |
|
240
|
|
|
*/ |
|
241
|
|
|
public function getActionButtonsAttribute() |
|
242
|
|
|
{ |
|
243
|
|
|
if ($this->trashed()) { |
|
|
|
|
|
|
244
|
|
|
return ' |
|
245
|
|
|
<div class="btn-group" role="group" aria-label="'.__('labels.backend.access.users.user_actions').'"> |
|
246
|
|
|
'.$this->restore_button.' |
|
247
|
|
|
'.$this->delete_permanently_button.' |
|
248
|
|
|
</div>'; |
|
249
|
|
|
} |
|
250
|
|
|
|
|
251
|
|
|
return ' |
|
252
|
|
|
<div class="btn-group" role="group" aria-label="'.__('labels.backend.access.users.user_actions').'"> |
|
253
|
|
|
'.$this->show_button.' |
|
254
|
|
|
'.$this->edit_button.' |
|
255
|
|
|
|
|
256
|
|
|
<div class="btn-group btn-group-sm" role="group"> |
|
257
|
|
|
<button id="userActions" type="button" class="btn btn-secondary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> |
|
258
|
|
|
'.__('labels.general.more').' |
|
259
|
|
|
</button> |
|
260
|
|
|
<div class="dropdown-menu" aria-labelledby="userActions"> |
|
261
|
|
|
'.$this->clear_session_button.' |
|
262
|
|
|
'.$this->login_as_button.' |
|
263
|
|
|
'.$this->change_password_button.' |
|
264
|
|
|
'.$this->status_button.' |
|
265
|
|
|
'.$this->confirmed_button.' |
|
266
|
|
|
'.$this->delete_button.' |
|
267
|
|
|
</div> |
|
268
|
|
|
</div> |
|
269
|
|
|
</div>'; |
|
270
|
|
|
} |
|
271
|
|
|
} |
|
272
|
|
|
|