1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Slides\Connector\Auth\Sync; |
4
|
|
|
|
5
|
|
|
use Carbon\Carbon; |
6
|
|
|
use Illuminate\Support\Arr; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Class User describes a remote user |
10
|
|
|
* |
11
|
|
|
* @package Slides\Connector\Auth\Sync |
12
|
|
|
*/ |
13
|
|
|
final class User |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* User's remote ID |
17
|
|
|
* |
18
|
|
|
* @var int |
19
|
|
|
*/ |
20
|
|
|
protected $remoteId; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* User's name |
24
|
|
|
* |
25
|
|
|
* @var string |
26
|
|
|
*/ |
27
|
|
|
protected $name; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* User's email |
31
|
|
|
* |
32
|
|
|
* @var string |
33
|
|
|
*/ |
34
|
|
|
protected $email; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* User's country code |
38
|
|
|
* |
39
|
|
|
* @var string |
40
|
|
|
*/ |
41
|
|
|
protected $country; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* User's encrypted password |
45
|
|
|
* |
46
|
|
|
* @var string |
47
|
|
|
*/ |
48
|
|
|
protected $password; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* The date of last update. |
52
|
|
|
* |
53
|
|
|
* @var Carbon |
54
|
|
|
*/ |
55
|
|
|
protected $updated; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* The creation date. |
59
|
|
|
* |
60
|
|
|
* @var Carbon |
61
|
|
|
*/ |
62
|
|
|
protected $created; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* The deletion date. |
66
|
|
|
* |
67
|
|
|
* @var Carbon|null |
68
|
|
|
*/ |
69
|
|
|
protected $deleted; |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* The instance of the user locally |
73
|
|
|
* |
74
|
|
|
* @var \Illuminate\Contracts\Auth\Authenticatable |
75
|
|
|
*/ |
76
|
|
|
protected $localUser; |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Whether a user exist only locally |
80
|
|
|
* |
81
|
|
|
* @var bool |
82
|
|
|
*/ |
83
|
|
|
protected $isLocal = false; |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* The action for a remote sync client |
87
|
|
|
* |
88
|
|
|
* @var string |
89
|
|
|
*/ |
90
|
|
|
protected $remoteAction; |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* User constructor. |
94
|
|
|
* |
95
|
|
|
* @param int $remoteId |
96
|
|
|
* @param string|null $name |
97
|
|
|
* @param string $email |
98
|
|
|
* @param string|null $password |
99
|
|
|
* @param string|null $updated |
100
|
|
|
* @param string $created |
101
|
|
|
* @param string|null $country |
102
|
|
|
* @param string|null $deleted |
103
|
|
|
* @param string $action |
104
|
|
|
*/ |
105
|
|
|
public function __construct( |
106
|
|
|
int $remoteId, |
107
|
|
|
?string $name, |
108
|
|
|
string $email, |
109
|
|
|
?string $password, |
110
|
|
|
?string $updated, |
111
|
|
|
string $created, |
112
|
|
|
?string $deleted, |
113
|
|
|
?string $country, |
114
|
|
|
string $action = null |
115
|
|
|
) |
116
|
|
|
{ |
117
|
|
|
$this->remoteId = $remoteId; |
118
|
|
|
$this->name = $name; |
119
|
|
|
$this->email = $email; |
120
|
|
|
$this->password = $password; |
121
|
|
|
$this->updated = new Carbon($updated); |
122
|
|
|
$this->created = new Carbon($created); |
123
|
|
|
$this->country = $country; |
124
|
|
|
$this->deleted = ($deleted ? new Carbon($deleted) : null); |
125
|
|
|
$this->remoteAction = $action; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* Get user's name |
130
|
|
|
* |
131
|
|
|
* @return string|null |
132
|
|
|
*/ |
133
|
|
|
public function getName() |
134
|
|
|
{ |
135
|
|
|
return $this->name; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* Get user's email |
140
|
|
|
* |
141
|
|
|
* @return string |
142
|
|
|
*/ |
143
|
|
|
public function getEmail(): string |
144
|
|
|
{ |
145
|
|
|
return $this->email; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* Get user's password |
150
|
|
|
* |
151
|
|
|
* @return string|null |
152
|
|
|
*/ |
153
|
|
|
public function getPassword() |
154
|
|
|
{ |
155
|
|
|
return $this->password; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* Get a creation date. |
160
|
|
|
* |
161
|
|
|
* @return Carbon |
162
|
|
|
*/ |
163
|
|
|
public function getCreated(): Carbon |
164
|
|
|
{ |
165
|
|
|
return $this->created; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* Get updated_at date |
170
|
|
|
* |
171
|
|
|
* @return Carbon|null |
172
|
|
|
*/ |
173
|
|
|
public function getUpdated() |
174
|
|
|
{ |
175
|
|
|
return $this->updated; |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* Get remote action |
180
|
|
|
* |
181
|
|
|
* @return string|null |
182
|
|
|
*/ |
183
|
|
|
public function getRemoteAction(): ?string |
184
|
|
|
{ |
185
|
|
|
return $this->remoteAction; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* Get remote user ID |
190
|
|
|
* |
191
|
|
|
* @return int |
192
|
|
|
*/ |
193
|
|
|
public function getRemoteId(): int |
194
|
|
|
{ |
195
|
|
|
return $this->remoteId; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* Get user's country |
200
|
|
|
* |
201
|
|
|
* @return string|null |
202
|
|
|
*/ |
203
|
|
|
public function getCountry() |
204
|
|
|
{ |
205
|
|
|
return $this->country; |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
/** |
209
|
|
|
* Reset the password. |
210
|
|
|
* |
211
|
|
|
* @return void |
212
|
|
|
*/ |
213
|
|
|
public function resetPassword() |
214
|
|
|
{ |
215
|
|
|
$this->password = null; |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
/** |
219
|
|
|
* Create a user from the response |
220
|
|
|
* |
221
|
|
|
* @param array $response |
222
|
|
|
* |
223
|
|
|
* @return static |
224
|
|
|
*/ |
225
|
|
|
public static function createFromResponse(array $response) |
226
|
|
|
{ |
227
|
|
|
$user = Arr::get($response, 'user'); |
228
|
|
|
|
229
|
|
|
return new static( |
230
|
|
|
Arr::get($user, 'id'), |
|
|
|
|
231
|
|
|
Arr::get($user, 'name'), |
232
|
|
|
Arr::get($user, 'email'), |
|
|
|
|
233
|
|
|
Arr::get($user, 'password'), |
234
|
|
|
Arr::get($user, 'updated_at'), |
235
|
|
|
Arr::get($user, 'created_at'), |
|
|
|
|
236
|
|
|
Arr::get($user, 'deleted_at'), |
237
|
|
|
Arr::get($user, 'country'), |
238
|
|
|
Arr::get($user, 'action') |
239
|
|
|
); |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
/** |
243
|
|
|
* Get a deletion date. |
244
|
|
|
* |
245
|
|
|
* @return Carbon|null |
246
|
|
|
*/ |
247
|
|
|
public function getDeleted(): ?Carbon |
248
|
|
|
{ |
249
|
|
|
return $this->deleted; |
250
|
|
|
} |
251
|
|
|
} |