1
|
|
|
<?php
|
2
|
|
|
|
3
|
|
|
namespace NukaCode\Users\Models;
|
4
|
|
|
|
5
|
|
|
use App\Models\BaseModel;
|
6
|
|
|
use Illuminate\Auth\Authenticatable;
|
7
|
|
|
use Illuminate\Auth\Passwords\CanResetPassword;
|
8
|
|
|
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
|
9
|
|
|
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
|
10
|
|
|
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
|
11
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
12
|
|
|
use Illuminate\Foundation\Auth\Access\Authorizable;
|
13
|
|
|
use NukaCode\Users\Traits\HasRoles;
|
14
|
|
|
|
15
|
|
|
abstract class User extends BaseModel implements AuthenticatableContract, AuthorizableContract, CanResetPasswordContract
|
16
|
|
|
{
|
17
|
|
|
use Authenticatable, Authorizable, CanResetPassword, HasRoles, SoftDeletes;
|
18
|
|
|
|
19
|
|
|
/**
|
20
|
|
|
* Define the SQL table for this model
|
21
|
|
|
*
|
22
|
|
|
* @var string
|
23
|
|
|
*/
|
24
|
|
|
protected $table = 'users';
|
25
|
|
|
|
26
|
|
|
/**
|
27
|
|
|
* The attributes excluded from the model's JSON form.
|
28
|
|
|
*
|
29
|
|
|
* @var array
|
30
|
|
|
*/
|
31
|
|
|
protected $hidden = [
|
32
|
|
|
'password',
|
33
|
|
|
'remember_token',
|
34
|
|
|
];
|
35
|
|
|
|
36
|
|
|
protected $fillable = [
|
37
|
|
|
'username',
|
38
|
|
|
'password',
|
39
|
|
|
'email',
|
40
|
|
|
'first_name',
|
41
|
|
|
'last_name',
|
42
|
|
|
'display_name',
|
43
|
|
|
'timezone',
|
44
|
|
|
'location',
|
45
|
|
|
'url',
|
46
|
|
|
'social_id',
|
47
|
|
|
'social_avatar',
|
48
|
|
|
];
|
49
|
|
|
|
50
|
|
|
/**
|
51
|
|
|
* Tell eloquent to set deleted_at as a carbon date.
|
52
|
|
|
*
|
53
|
|
|
* @var array
|
54
|
|
|
*/
|
55
|
|
|
protected $dates = [
|
56
|
|
|
'deleted_at',
|
57
|
|
|
];
|
58
|
|
|
|
59
|
|
|
/**
|
60
|
|
|
* Determines if the users has global rights.
|
61
|
|
|
*
|
62
|
|
|
* @return mixed
|
63
|
|
|
*/
|
64
|
|
View Code Duplication |
public function isSuperUser()
|
65
|
|
|
{
|
66
|
|
|
if (config('nukacode-user.allow_super_user') == true
|
67
|
|
|
&& $this->super_flag == 1
|
68
|
|
|
) {
|
69
|
|
|
return true;
|
70
|
|
|
}
|
71
|
|
|
|
72
|
|
|
return false;
|
73
|
|
|
}
|
74
|
|
|
|
75
|
|
|
/**
|
76
|
|
|
* Grant a user global rights.
|
77
|
|
|
*
|
78
|
|
|
* @return mixed
|
79
|
|
|
*/
|
80
|
|
View Code Duplication |
public function makeSuperUser()
|
81
|
|
|
{
|
82
|
|
|
if (config('nukacode-user.allow_super_user') == true) {
|
83
|
|
|
$this->super_flag = 1;
|
84
|
|
|
$this->save();
|
85
|
|
|
|
86
|
|
|
return true;
|
87
|
|
|
}
|
88
|
|
|
|
89
|
|
|
return false;
|
90
|
|
|
}
|
91
|
|
|
|
92
|
|
|
/**
|
93
|
|
|
* Order by name ascending scope
|
94
|
|
|
*
|
95
|
|
|
* @param Builder $query The current query to append to
|
96
|
|
|
*
|
97
|
|
|
* @return Builder
|
98
|
|
|
*/
|
99
|
|
|
public function scopeOrderByNameAsc($query)
|
100
|
|
|
{
|
101
|
|
|
return $query->orderBy('username', 'asc');
|
102
|
|
|
}
|
103
|
|
|
|
104
|
|
|
/**
|
105
|
|
|
* Make sure to hash the user's password on save
|
106
|
|
|
*
|
107
|
|
|
* @param string $value The value of the attribute (Auto Set)
|
108
|
|
|
*/
|
109
|
|
|
public function setPasswordAttribute($value)
|
110
|
|
|
{
|
111
|
|
|
$this->attributes['password'] = bcrypt($value);
|
112
|
|
|
}
|
113
|
|
|
}
|
114
|
|
|
|