Completed
Push — master ( b16b0c...25ed1d )
by Travis
02:16
created

User::getRememberTokenName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
dl 0
loc 4
rs 10
c 3
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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
        'email',
39
        'first_name',
40
        'last_name',
41
        'display_name',
42
        'timezone',
43
        'location',
44
        'url',
45
        'social_id',
46
        'social_avatar',
47
        'super_flag',
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
    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
     * Order by name ascending scope
77
     *
78
     * @param Builder $query The current query to append to
79
     *
80
     * @return Builder
81
     */
82
    public function scopeOrderByNameAsc($query)
83
    {
84
        return $query->orderBy('username', 'asc');
85
    }
86
87
    /**
88
     * Make sure to hash the user's password on save
89
     *
90
     * @param string $value The value of the attribute (Auto Set)
91
     */
92
    public function setPasswordAttribute($value)
93
    {
94
        $this->attributes['password'] = bcrypt($value);
95
    }
96
}
97