-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUser.php
126 lines (106 loc) · 3.12 KB
/
User.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?php
namespace Vanguard;
use Illuminate\Notifications\Notifiable;
use Tymon\JWTAuth\Contracts\JWTSubject;
use Vanguard\Presenters\UserPresenter;
use Vanguard\Services\Auth\Api\TokenFactory;
use Vanguard\Services\Auth\TwoFactor\Authenticatable as TwoFactorAuthenticatable;
use Vanguard\Services\Auth\TwoFactor\Contracts\Authenticatable as TwoFactorAuthenticatableContract;
use Vanguard\Services\Logging\UserActivity\Activity;
use Vanguard\Support\Authorization\AuthorizationUserTrait;
use Vanguard\Support\Enum\UserStatus;
use Illuminate\Auth\Passwords\CanResetPassword;
use Laracasts\Presenter\PresentableTrait;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable implements TwoFactorAuthenticatableContract, JWTSubject
{
use TwoFactorAuthenticatable,
CanResetPassword,
PresentableTrait,
AuthorizationUserTrait,
Notifiable;
protected $presenter = UserPresenter::class;
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'users';
protected $dates = ['last_login', 'birthday'];
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'email', 'password', 'username', 'first_name', 'last_name', 'phone', 'avatar',
'address', 'country_id', 'birthday', 'last_login', 'confirmation_token', 'status',
'remember_token', 'role_id'
];
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
protected $hidden = ['password', 'remember_token'];
/**
* Always encrypt password when it is updated.
*
* @param $value
* @return string
*/
public function setPasswordAttribute($value)
{
$this->attributes['password'] = bcrypt($value);
}
public function setBirthdayAttribute($value)
{
$this->attributes['birthday'] = trim($value) ?: null;
}
public function gravatar()
{
$hash = hash('md5', strtolower(trim($this->attributes['email'])));
return sprintf("https://www.gravatar.com/avatar/%s?size=150", $hash);
}
public function isUnconfirmed()
{
return $this->status == UserStatus::UNCONFIRMED;
}
public function isActive()
{
return $this->status == UserStatus::ACTIVE;
}
public function isBanned()
{
return $this->status == UserStatus::BANNED;
}
public function country()
{
return $this->belongsTo(Country::class, 'country_id');
}
public function activities()
{
return $this->hasMany(Activity::class, 'user_id');
}
/**
* Get the identifier that will be stored in the subject claim of the JWT.
*
* @return mixed
*/
public function getJWTIdentifier()
{
return $this->id;
}
/**
* Return a key value array, containing any custom claims to be added to the JWT.
*
* @return array
*/
public function getJWTCustomClaims()
{
$token = app(TokenFactory::class)->forUser($this);
return [
'jti' => $token->id
];
}
}