forked from johndavedecano/laragym
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUser.php
146 lines (129 loc) · 3 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<?php
/**
* Created by John Dave Decano<johndavedecano@gmail.com>.
* Date: Mon, 16 Apr 2018 18:21:38 +0000.
*/
namespace App\Models;
use App\Notifications\ForgotPassword;
use Hash;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Tymon\JWTAuth\Contracts\JWTSubject;
/**
* Class User
*
* @property int $id
* @property string $name
* @property string $email
* @property string $password
* @property string $remember_token
* @property \Carbon\Carbon $created_at
* @property \Carbon\Carbon $updated_at
* @property string $account_number
* @property string $mobile
* @property string $avatar
* @property \Carbon\Carbon $date_of_birth
* @property string $address
* @property string $city
* @property string $state
* @property string $postal_code
* @property bool $is_admin
* @property \Carbon\Carbon $last_login
*
* @package App\Models
*/
class User extends Authenticatable implements JWTSubject
{
use Notifiable;
use HasSubscriptions;
protected $casts = [
'is_admin' => 'bool',
'is_active' => 'bool',
'is_deleted' => 'bool'
];
protected $dates = [
'last_login'
];
protected $hidden = [
'password',
'remember_token'
];
protected $fillable = [
'name',
'email',
'password',
'remember_token',
'account_number',
'mobile',
'avatar',
'date_of_birth',
'address',
'city',
'state',
'postal_code',
'country',
'is_admin',
'is_deleted',
'last_login'
];
/**
* Save the last login timestamp.
*
* @return object
*/
public function logLastLogin()
{
$this->last_login = date('Y-m-d H:i:s');
$this->save();
return $this;
}
/**
* Automatically create user account number.
*
* @param string $value
* @return void
*/
public function setAccountNumberAttribute($value)
{
$random = rand(10, 500);
$this->attributes['account_number'] = $value.$random;
}
/**
* Automatically creates hash for the user password.
*
* @param string $value
* @return void
*/
public function setPasswordAttribute($value)
{
$this->attributes['password'] = Hash::make($value);
}
/**
* Get the identifier that will be stored in the subject claim of the JWT.
*
* @return mixed
*/
public function getJWTIdentifier()
{
return $this->getKey();
}
/**
* Return a key value array, containing any custom claims to be added to the JWT.
*
* @return array
*/
public function getJWTCustomClaims()
{
return [];
}
/**
* Send the password reset notification.
*
* @param string $token
* @return void
*/
public function sendPasswordResetNotification($token)
{
$this->notify(new ForgotPassword($token));
}
}