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