forked from anonaddy/anonaddy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Recipient.php
115 lines (96 loc) · 2.33 KB
/
Recipient.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
<?php
namespace App;
use App\Traits\HasEncryptedAttributes;
use App\Traits\HasUuid;
use Illuminate\Auth\Notifications\VerifyEmail;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notifiable;
class Recipient extends Model
{
use Notifiable, HasUuid, HasEncryptedAttributes;
public $incrementing = false;
protected $keyType = 'string';
protected $encrypted = [
'email',
'fingerprint'
];
protected $fillable = [
'email',
'user_id',
'should_encrypt',
'fingerprint',
'email_verified_at'
];
protected $dates = [
'created_at',
'updated_at',
'email_verified_at'
];
protected $casts = [
'id' => 'string',
'user_id' => 'string',
'should_encrypt' => 'boolean'
];
public static function boot()
{
parent::boot();
Recipient::deleting(function ($recipient) {
if ($recipient->fingerprint) {
$recipient->user->deleteKeyFromKeyring($recipient->fingerprint);
}
$recipient->aliases()->detach();
});
}
/**
* Get the user the recipient belongs to.
*/
public function user()
{
return $this->belongsTo(User::class);
}
/**
* Get the aliases that have this recipient attached.
*/
public function aliases()
{
return $this->belongsToMany(Alias::class, 'alias_recipients')->using(AliasRecipient::class);
}
/**
* Determine if the recipient has a verified email address.
*
* @return bool
*/
public function hasVerifiedEmail()
{
return ! is_null($this->email_verified_at);
}
/**
* Mark this recipient's email as verified.
*
* @return bool
*/
public function markEmailAsVerified()
{
return $this->forceFill([
'email_verified_at' => $this->freshTimestamp(),
])->save();
}
/**
* Send the email verification notification.
*
* @return void
*/
public function sendEmailVerificationNotification()
{
$this->notify(new VerifyEmail);
}
/**
* Get the email address that should be used for verification.
*
* @return string
*/
public function getEmailForVerification()
{
return $this->email;
}
}