1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Slides\Connector\Auth\Concerns; |
4
|
|
|
|
5
|
|
|
use Slides\Connector\Auth\Notifications\ResetPasswordNotification; |
6
|
|
|
use Illuminate\Auth\Passwords\CanResetPassword; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Trait UserHelpers |
10
|
|
|
* |
11
|
|
|
* @package Slides\Connector\Auth\Concerns |
12
|
|
|
*/ |
13
|
|
|
trait UserHelpers |
14
|
|
|
{ |
15
|
|
|
use CanResetPassword; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @inheritdoc |
19
|
|
|
*/ |
20
|
|
|
public function retrieveId() |
21
|
|
|
{ |
22
|
|
|
return $this->id; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @inheritdoc |
27
|
|
|
*/ |
28
|
|
|
public function retrieveRemoteId() |
29
|
|
|
{ |
30
|
|
|
return $this->remote_id; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @inheritdoc |
35
|
|
|
*/ |
36
|
|
|
public function retrieveName() |
37
|
|
|
{ |
38
|
|
|
return $this->name; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @inheritdoc |
43
|
|
|
*/ |
44
|
|
|
public function retrieveEmail() |
45
|
|
|
{ |
46
|
|
|
return $this->email; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @inheritdoc |
51
|
|
|
*/ |
52
|
|
|
public function retrievePassword() |
53
|
|
|
{ |
54
|
|
|
return $this->password; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @inheritdoc |
59
|
|
|
*/ |
60
|
|
|
public function retrieveCreatedAt() |
61
|
|
|
{ |
62
|
|
|
return $this->created_at; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @inheritdoc |
67
|
|
|
*/ |
68
|
|
|
public function retrieveUpdatedAt() |
69
|
|
|
{ |
70
|
|
|
return $this->updated_at; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @inheritdoc |
75
|
|
|
*/ |
76
|
|
|
public function retrieveDeletedAt() |
77
|
|
|
{ |
78
|
|
|
return $this->deleted_at; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Send the password reset notification. |
83
|
|
|
* |
84
|
|
|
* @param string $token |
85
|
|
|
* |
86
|
|
|
* @return void |
87
|
|
|
*/ |
88
|
|
|
public function sendPasswordResetNotification($token) |
89
|
|
|
{ |
90
|
|
|
$this->notify(new ResetPasswordNotification($token)); |
|
|
|
|
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Transform user's email to "deleted email". |
95
|
|
|
* |
96
|
|
|
* @param string $email |
97
|
|
|
* @param int $index |
98
|
|
|
* |
99
|
|
|
* @return string |
100
|
|
|
*/ |
101
|
|
|
public static function deleteEmail(string $email, int $index): string |
102
|
|
|
{ |
103
|
|
|
if(strpos($email, ".{$index}.deleted" !== false)) { |
104
|
|
|
return $email; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
return "{$email}.{$index}.deleted"; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Transform user's "deleted email" to an original one. |
112
|
|
|
* |
113
|
|
|
* @param string $email |
114
|
|
|
* @param int $index |
115
|
|
|
* |
116
|
|
|
* @return string |
117
|
|
|
*/ |
118
|
|
|
public static function restoreEmail(string $email, int $index): string |
119
|
|
|
{ |
120
|
|
|
return str_replace(".{$index}.deleted", '', $email); |
121
|
|
|
} |
122
|
|
|
} |