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