1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace MrShan0\WordpressAuth\Models; |
4
|
|
|
|
5
|
|
|
use Illuminate\Database\Eloquent\Model; |
6
|
|
|
use Illuminate\Foundation\Auth\User as Authenticatable; |
7
|
|
|
use Illuminate\Notifications\Notifiable; |
8
|
|
|
use Illuminate\Support\Str; |
9
|
|
|
|
10
|
|
|
class WordpressUser extends Authenticatable |
11
|
|
|
{ |
12
|
|
|
use Notifiable; |
|
|
|
|
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Explicitly define your table name |
16
|
|
|
* |
17
|
|
|
* @var string |
18
|
|
|
*/ |
19
|
|
|
protected $table = 'users'; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Disable timestamps |
23
|
|
|
* |
24
|
|
|
* @var boolean |
25
|
|
|
*/ |
26
|
|
|
public $timestamps = false; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Define primary key |
30
|
|
|
* |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
protected $primaryKey = 'ID'; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* The column name of the "remember me" token. |
37
|
|
|
* |
38
|
|
|
* @var string |
39
|
|
|
*/ |
40
|
|
|
protected $rememberTokenName = false; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* The attributes that should be mutated to dates. |
44
|
|
|
* |
45
|
|
|
* @var array |
46
|
|
|
*/ |
47
|
|
|
protected $dates = [ |
48
|
|
|
'user_registered', |
49
|
|
|
]; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* The attributes that should be hidden for arrays. |
53
|
|
|
* |
54
|
|
|
* @var array |
55
|
|
|
*/ |
56
|
|
|
protected $hidden = [ |
57
|
|
|
'user_pass', |
58
|
|
|
'remember_token', // disabled via protected property |
59
|
|
|
]; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* The attributes that are mass assignable. |
63
|
|
|
* |
64
|
|
|
* @var array |
65
|
|
|
*/ |
66
|
|
|
protected $fillable = [ |
67
|
|
|
'user_login', |
68
|
|
|
'user_pass', |
69
|
|
|
'user_nicename', |
70
|
|
|
'user_email', |
71
|
|
|
'user_url', |
72
|
|
|
'user_registered', |
73
|
|
|
'user_activation_key', |
74
|
|
|
'user_status', |
75
|
|
|
'display_name', |
76
|
|
|
]; |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Create a new Eloquent model instance. |
80
|
|
|
* |
81
|
|
|
* @param array $attributes |
82
|
|
|
* @return void |
83
|
|
|
*/ |
84
|
|
|
public function __construct(array $attributes = []) |
85
|
|
|
{ |
86
|
|
|
parent::__construct($attributes); |
87
|
|
|
|
88
|
|
|
// Set connection via config explicitly. |
89
|
|
|
$this->setConnection(config('wordpress-auth.connection', 'mysql')); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Accessor to update password via Auth scaffolding |
94
|
|
|
*/ |
95
|
|
|
public function setPasswordAttribute($value) |
96
|
|
|
{ |
97
|
|
|
$this->attributes[$this->getPasswordColumnKey()] = $value; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Return the key used for email in wordpress schema |
102
|
|
|
* |
103
|
|
|
* @return string |
104
|
|
|
*/ |
105
|
|
|
public function getEmailColumnKey() |
106
|
|
|
{ |
107
|
|
|
return config('wordpress-auth.options.email_column', 'user_email'); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Return the key used for password in wordpress schema |
112
|
|
|
* |
113
|
|
|
* @return string |
114
|
|
|
*/ |
115
|
|
|
public function getPasswordColumnKey() |
116
|
|
|
{ |
117
|
|
|
return config('wordpress-auth.options.password_column', 'user_pass'); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Get the e-mail address where password reset links are sent. |
122
|
|
|
* |
123
|
|
|
* @return string |
124
|
|
|
*/ |
125
|
|
|
public function getEmailForPasswordReset() |
126
|
|
|
{ |
127
|
|
|
return $this->{$this->getEmailColumnKey()}; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Return password value |
132
|
|
|
* |
133
|
|
|
* @return string |
134
|
|
|
*/ |
135
|
|
|
public function getAuthPassword() |
136
|
|
|
{ |
137
|
|
|
return $this->{$this->getPasswordColumnKey()}; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* Usage for notifiable for email |
142
|
|
|
* |
143
|
|
|
* @return string |
144
|
|
|
*/ |
145
|
|
|
public function routeNotificationForMail() |
146
|
|
|
{ |
147
|
|
|
return $this->getEmailForPasswordReset(); |
148
|
|
|
} |
149
|
|
|
} |
150
|
|
|
|