1
|
|
|
<?php namespace App\Modules\Acl; |
2
|
|
|
|
3
|
|
|
use App\User; |
4
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes; |
5
|
|
|
use Illuminate\Notifications\Notifiable; |
6
|
|
|
use Laravel\Passport\HasApiTokens; |
7
|
|
|
|
8
|
|
|
class AclUser extends User { |
9
|
|
|
|
10
|
|
|
use SoftDeletes, HasApiTokens; |
11
|
|
|
protected $table = 'users'; |
12
|
|
|
protected $dates = ['created_at', 'updated_at', 'deleted_at']; |
13
|
|
|
protected $hidden = ['password', 'remember_token', 'deleted_at']; |
14
|
|
|
protected $guarded = ['id']; |
15
|
|
|
protected $fillable = ['profile_picture', 'name', 'email', 'password', 'locale', 'time_zone']; |
16
|
|
|
public $searchable = ['name', 'email']; |
17
|
|
|
|
18
|
|
|
public function getCreatedAtAttribute($value) |
19
|
|
|
{ |
20
|
|
|
return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString(); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function getUpdatedAtAttribute($value) |
24
|
|
|
{ |
25
|
|
|
return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString(); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function getDeletedAtAttribute($value) |
29
|
|
|
{ |
30
|
|
|
return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString(); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Get the profile picture url. |
35
|
|
|
* @return string |
36
|
|
|
*/ |
37
|
|
|
public function getProfilePictureAttribute($value) |
38
|
|
|
{ |
39
|
|
|
return url(\Storage::url($value)); |
|
|
|
|
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Encrypt the password attribute before |
44
|
|
|
* saving it in the storage. |
45
|
|
|
* |
46
|
|
|
* @param string $value |
47
|
|
|
*/ |
48
|
|
|
public function setPasswordAttribute($value) |
49
|
|
|
{ |
50
|
|
|
$this->attributes['password'] = bcrypt($value); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Get the entity's notifications. |
55
|
|
|
*/ |
56
|
|
|
public function notifications() |
57
|
|
|
{ |
58
|
|
|
return $this->morphMany('\App\Modules\Notifications\Notification', 'notifiable')->orderBy('created_at', 'desc'); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Get the entity's read notifications. |
63
|
|
|
*/ |
64
|
|
|
public function readNotifications() |
65
|
|
|
{ |
66
|
|
|
return $this->notifications()->whereNotNull('read_at'); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Get the entity's unread notifications. |
71
|
|
|
*/ |
72
|
|
|
public function unreadNotifications() |
73
|
|
|
{ |
74
|
|
|
return $this->notifications()->whereNull('read_at'); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function groups() |
78
|
|
|
{ |
79
|
|
|
return $this->belongsToMany('\App\Modules\Acl\AclGroup', 'users_groups', 'user_id', 'group_id')->whereNull('users_groups.deleted_at')->withTimestamps(); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function oauthClients() |
83
|
|
|
{ |
84
|
|
|
return $this->hasMany('App\Modules\Acl\OauthClient', 'user_id'); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Return fcm device tokens that will be used in sending fcm notifications. |
89
|
|
|
* |
90
|
|
|
* @return array |
91
|
|
|
*/ |
92
|
|
|
public function routeNotificationForFCM() |
93
|
|
|
{ |
94
|
|
|
$devices = \Core::pushNotificationDevices()->findBy(['user_id' => $this->id]); |
95
|
|
|
$tokens = []; |
96
|
|
|
|
97
|
|
|
foreach ($devices as $device) |
98
|
|
|
{ |
99
|
|
|
try |
100
|
|
|
{ |
101
|
|
|
if (\Core::users()->accessTokenExpiredOrRevoked($device->access_token)) |
102
|
|
|
{ |
103
|
|
|
continue; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
$tokens[] = $device->device_token; |
107
|
|
|
} |
108
|
|
|
catch (\Exception $e) |
109
|
|
|
{ |
110
|
|
|
$device->forceDelete(); |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
return $tokens; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* The channels the user receives notification broadcasts on. |
119
|
|
|
* |
120
|
|
|
* @return string |
121
|
|
|
*/ |
122
|
|
|
public function receivesBroadcastNotificationsOn() |
123
|
|
|
{ |
124
|
|
|
return 'users.'.$this->id; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Custom password validation. |
129
|
|
|
* |
130
|
|
|
* @param string $password |
131
|
|
|
* @return boolean |
132
|
|
|
*/ |
133
|
|
|
public function validateForPassportPasswordGrant($password) |
134
|
|
|
{ |
135
|
|
|
if ($password == config('skeleton.social_pass')) |
136
|
|
|
{ |
137
|
|
|
return true; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
return \Hash::check($password, $this->password); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
public static function boot() |
144
|
|
|
{ |
145
|
|
|
parent::boot(); |
146
|
|
|
AclUser::observe(\App::make('App\Modules\Acl\ModelObservers\AclUserObserver')); |
147
|
|
|
} |
148
|
|
|
} |
149
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.