|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Models; |
|
4
|
|
|
|
|
5
|
|
|
use PragmaRX\Google2FA\Google2FA; |
|
6
|
|
|
use Illuminate\Notifications\Notifiable; |
|
7
|
|
|
use Illuminate\Foundation\Auth\User as Authenticatable; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* @property mixed google2fa_secret |
|
11
|
|
|
* @property mixed id |
|
12
|
|
|
*/ |
|
13
|
|
|
class User extends Authenticatable |
|
14
|
|
|
{ |
|
15
|
|
|
use Notifiable; |
|
|
|
|
|
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* The attributes that are mass assignable. |
|
19
|
|
|
* |
|
20
|
|
|
* @var array |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $fillable = [ |
|
23
|
|
|
'username', |
|
24
|
|
|
'email', |
|
25
|
|
|
'password', |
|
26
|
|
|
'preferences', |
|
27
|
|
|
]; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* The attributes that should be hidden for arrays. |
|
31
|
|
|
* |
|
32
|
|
|
* @var array |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $hidden = [ |
|
35
|
|
|
'password', |
|
36
|
|
|
'remember_token', |
|
37
|
|
|
]; |
|
38
|
|
|
|
|
39
|
|
|
protected $casts = [ |
|
40
|
|
|
'preferences' => 'array', |
|
41
|
|
|
]; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany |
|
45
|
|
|
*/ |
|
46
|
|
|
public function subscription() |
|
47
|
|
|
{ |
|
48
|
|
|
return $this->hasMany(Subscription::class); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany |
|
53
|
|
|
*/ |
|
54
|
|
|
public function mailingList() |
|
55
|
|
|
{ |
|
56
|
|
|
return $this->hasMany(MailingList::class); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany |
|
61
|
|
|
*/ |
|
62
|
|
|
public function template() |
|
63
|
|
|
{ |
|
64
|
|
|
return $this->hasMany(Template::class); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany |
|
69
|
|
|
*/ |
|
70
|
|
|
public function campaigns() |
|
71
|
|
|
{ |
|
72
|
|
|
return $this->hasMany(Campaign::class); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public function generate2faKey() |
|
76
|
|
|
{ |
|
77
|
|
|
if (! $this->google2fa_secret) { |
|
78
|
|
|
$google2fa = new Google2FA(); |
|
79
|
|
|
|
|
80
|
|
|
$this->google2fa_secret = $google2fa->generateSecretKey(); |
|
81
|
|
|
$this->save(); |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
public function verifyKey($secret) |
|
86
|
|
|
{ |
|
87
|
|
|
$google2fa = new Google2FA(); |
|
88
|
|
|
|
|
89
|
|
|
return $google2fa->verifyKey($this->google2fa_secret, $secret); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
public function twoFactorBackupCodes() |
|
93
|
|
|
{ |
|
94
|
|
|
return $this->hasMany(TwofactorBackupCodes::class, 'user_id'); |
|
|
|
|
|
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|