1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* User class |
4
|
|
|
* |
5
|
|
|
* This file describes the User classes |
6
|
|
|
* |
7
|
|
|
* PHP version 5 and 7 |
8
|
|
|
* |
9
|
|
|
* @author Patrick Boyd / [email protected] |
10
|
|
|
* @copyright Copyright (c) 2015, Austin Artistic Reconstruction |
11
|
|
|
* @license http://www.apache.org/licenses/ Apache 2.0 License |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Auth; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* A class to abstract access to Users regardless of the Authentication type used. |
18
|
|
|
* |
19
|
|
|
* This class is the primary method to access user information. |
20
|
|
|
*/ |
21
|
|
|
class User extends \SerializableObject |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* An array to cache the title to string mappings so that they don't need to be pulled from the database |
25
|
|
|
* everytime |
26
|
|
|
*/ |
27
|
|
|
public static $titlenames = null; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Is this user in the Group or a child of that group? |
31
|
|
|
* |
32
|
|
|
* @param string $name The name of the group to check if the user is in |
33
|
|
|
* |
34
|
|
|
* @return boolean True if the user is in the group, false otherwise |
35
|
|
|
*/ |
36
|
|
|
public function isInGroupNamed($name) |
37
|
|
|
{ |
38
|
|
|
return false; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function __get($propName) |
42
|
|
|
{ |
43
|
|
|
return false; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function __set($propName, $value) |
47
|
|
|
{ |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* The email address for the user |
52
|
|
|
* |
53
|
|
|
* @return boolean|string The user's email address |
54
|
|
|
*/ |
55
|
|
|
public function getEmail() |
56
|
|
|
{ |
57
|
|
|
return false; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* The user ID for the user |
62
|
|
|
* |
63
|
|
|
* @return boolean|string The user's ID or username |
64
|
|
|
*/ |
65
|
|
|
public function getUid() |
66
|
|
|
{ |
67
|
|
|
return $this->getEmail(); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* The photo for the user |
72
|
|
|
* |
73
|
|
|
* @return boolean|string The user's photo as a binary string |
74
|
|
|
*/ |
75
|
|
|
public function getPhoto() |
76
|
|
|
{ |
77
|
|
|
return false; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* The phone number for the user |
82
|
|
|
* |
83
|
|
|
* @return boolean|string The user's phone number |
84
|
|
|
*/ |
85
|
|
|
public function getPhoneNumber() |
86
|
|
|
{ |
87
|
|
|
return false; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* The organziation for the user |
92
|
|
|
* |
93
|
|
|
* @return boolean|string The user's organization |
94
|
|
|
*/ |
95
|
|
|
public function getOrganization() |
96
|
|
|
{ |
97
|
|
|
return false; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* The list of titles for the user |
102
|
|
|
* |
103
|
|
|
* @return boolean|array The user's title(s) in short format |
104
|
|
|
*/ |
105
|
|
|
public function getTitles() |
106
|
|
|
{ |
107
|
|
|
return false; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* The list of titles for the user |
112
|
|
|
* |
113
|
|
|
* @return boolean|array The user's title(s) in user friendly strings |
114
|
|
|
* |
115
|
|
|
* @SuppressWarnings("StaticAccess") |
116
|
|
|
*/ |
117
|
|
|
public function getTitleNames() |
118
|
|
|
{ |
119
|
|
|
$titles = $this->getTitles(); |
120
|
|
|
if($titles === false) |
121
|
|
|
{ |
122
|
|
|
return false; |
123
|
|
|
} |
124
|
|
|
if(self::$titlenames === null) |
125
|
|
|
{ |
126
|
|
|
$dataSet = \DataSetFactory::getDataSetByName('profiles'); |
127
|
|
|
$dataTable = $dataSet['position']; |
128
|
|
|
$titlenames = $dataTable->read(); |
129
|
|
|
self::$titlenames = array(); |
130
|
|
|
$count = count($titlenames); |
131
|
|
|
for($i = 0; $i < $count; $i++) |
132
|
|
|
{ |
133
|
|
|
self::$titlenames[$titlenames[$i]['short_name']] = $titlenames[$i]; |
134
|
|
|
} |
135
|
|
|
} |
136
|
|
|
$count = count($titles); |
137
|
|
|
for($i = 0; $i < $count; $i++) |
138
|
|
|
{ |
139
|
|
|
if(isset(self::$titlenames[$titles[$i]])) |
140
|
|
|
{ |
141
|
|
|
$title = self::$titlenames[$titles[$i]]; |
142
|
|
|
$titles[$i] = $title['name']; |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
return $titles; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* The state the user's mailing address is in |
150
|
|
|
* |
151
|
|
|
* @return boolean|string The user's state from their mailing address |
152
|
|
|
*/ |
153
|
|
|
public function getState() |
154
|
|
|
{ |
155
|
|
|
return false; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* The city the user's mailing address is in |
160
|
|
|
* |
161
|
|
|
* @return boolean|string The user's city from their mailing address |
162
|
|
|
*/ |
163
|
|
|
public function getCity() |
164
|
|
|
{ |
165
|
|
|
return false; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* The last name for the user |
170
|
|
|
* |
171
|
|
|
* @return boolean|string The user's last name |
172
|
|
|
*/ |
173
|
|
|
public function getLastName() |
174
|
|
|
{ |
175
|
|
|
return false; |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* The nick name for the user |
180
|
|
|
* |
181
|
|
|
* @return boolean|string The user's nick name |
182
|
|
|
*/ |
183
|
|
|
public function getNickName() |
184
|
|
|
{ |
185
|
|
|
return $this->getUid(); |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* The street address for the user |
190
|
|
|
* |
191
|
|
|
* @return boolean|string The user's street address |
192
|
|
|
*/ |
193
|
|
|
public function getAddress() |
194
|
|
|
{ |
195
|
|
|
return false; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* The postal (zip) code for the user's mailing address |
200
|
|
|
* |
201
|
|
|
* @return boolean|string The user's postal code |
202
|
|
|
*/ |
203
|
|
|
public function getPostalCode() |
204
|
|
|
{ |
205
|
|
|
return false; |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
/** |
209
|
|
|
* The country the user's mailing address is in |
210
|
|
|
* |
211
|
|
|
* @return boolean|string The user's country from their mailing address |
212
|
|
|
*/ |
213
|
|
|
public function getCountry() |
214
|
|
|
{ |
215
|
|
|
return false; |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
/** |
219
|
|
|
* The organizational units the user is in |
220
|
|
|
* |
221
|
|
|
* This is the same as Areas in Flipside speak. |
222
|
|
|
* |
223
|
|
|
* @return boolean|array The user's orgnaiational units |
224
|
|
|
*/ |
225
|
|
|
public function getOrganizationUnits() |
226
|
|
|
{ |
227
|
|
|
return false; |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
/** |
231
|
|
|
* The supplemental login types that the user can use to login |
232
|
|
|
* |
233
|
|
|
* @return boolean|array The user's login providers |
234
|
|
|
*/ |
235
|
|
|
public function getLoginProviders() |
236
|
|
|
{ |
237
|
|
|
return false; |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
/** |
241
|
|
|
* The groups the user is a part of |
242
|
|
|
* |
243
|
|
|
* @return boolean|array The user's Auth\Group structures |
244
|
|
|
*/ |
245
|
|
|
public function getGroups() |
246
|
|
|
{ |
247
|
|
|
return false; |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
/** |
251
|
|
|
* Add a supplemental login type that the user can use to login |
252
|
|
|
* |
253
|
|
|
* @param string $provider The hostname for the provider |
254
|
|
|
* |
255
|
|
|
* @return boolean true if the addition worked, false otherwise |
256
|
|
|
*/ |
257
|
|
|
public function addLoginProvider($provider) |
258
|
|
|
{ |
259
|
|
|
throw new \Exception('Cannot add provider for this login type!'); |
260
|
|
|
} |
261
|
|
|
|
262
|
|
|
/** |
263
|
|
|
* Can the user login with this provider? |
264
|
|
|
* |
265
|
|
|
* @param string $provider The hostname for the provider |
266
|
|
|
* |
267
|
|
|
* @return boolean true if they can login with the provider, false otherwise |
268
|
|
|
*/ |
269
|
|
|
public function canLoginWith($provider) |
270
|
|
|
{ |
271
|
|
|
$hosts = $this->getLoginProviders(); |
272
|
|
|
if($hosts === false) |
273
|
|
|
{ |
274
|
|
|
return false; |
275
|
|
|
} |
276
|
|
|
$count = count($hosts); |
277
|
|
|
for($i = 0; $i < $count; $i++) |
278
|
|
|
{ |
279
|
|
|
if(strcasecmp($hosts[$i], $provider) === 0) |
280
|
|
|
{ |
281
|
|
|
return true; |
282
|
|
|
} |
283
|
|
|
} |
284
|
|
|
return false; |
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
/** |
288
|
|
|
* Set the user's password without verifying the current password |
289
|
|
|
* |
290
|
|
|
* @param string $password The new user password |
291
|
|
|
* |
292
|
|
|
* @return boolean true if the user's password was changed, false otherwise |
293
|
|
|
*/ |
294
|
|
|
protected function setPass($password) |
295
|
|
|
{ |
296
|
|
|
return false; |
297
|
|
|
} |
298
|
|
|
|
299
|
|
|
/** |
300
|
|
|
* Has the user completely filled out their user profile? |
301
|
|
|
* |
302
|
|
|
* @return boolean true if the user's profile is complete, false otherwise |
303
|
|
|
*/ |
304
|
|
|
public function isProfileComplete() |
305
|
|
|
{ |
306
|
|
|
if($this->getCountry() === false || $this->getAddress() === false || |
307
|
|
|
$this->getPostalCode() === false || $this->getCity() === false || |
308
|
|
|
$this->getState() === false || $this->getPhoneNumber() === false) |
309
|
|
|
{ |
310
|
|
|
return false; |
311
|
|
|
} |
312
|
|
|
return true; |
313
|
|
|
} |
314
|
|
|
|
315
|
|
|
/** |
316
|
|
|
* Validate that the user's password is the specified password |
317
|
|
|
* |
318
|
|
|
* @param string $password The user's current password |
319
|
|
|
* |
320
|
|
|
* @return boolean true if the user's password is correct, false otherwise |
321
|
|
|
* |
322
|
|
|
* @SuppressWarnings("UnusedFormalParameter") |
323
|
|
|
*/ |
324
|
|
|
public function validate_password($password) |
325
|
|
|
{ |
326
|
|
|
return false; |
327
|
|
|
} |
328
|
|
|
|
329
|
|
|
/** |
330
|
|
|
* Validate that the user's reset hash is the sepcified hash |
331
|
|
|
* |
332
|
|
|
* @param string $hash The user's reset hash |
333
|
|
|
* |
334
|
|
|
* @return boolean true if the user's hash is correct, false otherwise |
335
|
|
|
* |
336
|
|
|
* @SuppressWarnings("UnusedFormalParameter") |
337
|
|
|
*/ |
338
|
|
|
public function validate_reset_hash($hash) |
339
|
|
|
{ |
340
|
|
|
return false; |
341
|
|
|
} |
342
|
|
|
|
343
|
|
|
/** |
344
|
|
|
* Change the user's password, validating the old password or reset hash |
345
|
|
|
* |
346
|
|
|
* @param string $oldpass The user's original password or reset hash if $isHash is true |
347
|
|
|
* @param string $newpass The user's new password |
348
|
|
|
* @param boolean $isHash Is $old_pass a password or a hash |
349
|
|
|
* |
350
|
|
|
* @return boolean true if the user's password was changed, false otherwise |
351
|
|
|
*/ |
352
|
|
|
public function change_pass($oldpass, $newpass, $isHash = false) |
353
|
|
|
{ |
354
|
|
|
if($isHash === false && $this->validate_password($oldpass) === false) |
355
|
|
|
{ |
356
|
|
|
throw new \Exception('Invalid Password!', 3); |
357
|
|
|
} |
358
|
|
|
if($isHash === true && $this->validate_reset_hash($oldpass) === false) |
359
|
|
|
{ |
360
|
|
|
throw new \Exception('Invalid Reset Hash!', 3); |
361
|
|
|
} |
362
|
|
|
if($this->setPass($newpass) === false) |
363
|
|
|
{ |
364
|
|
|
throw new \Exception('Unable to set password!', 6); |
365
|
|
|
} |
366
|
|
|
return true; |
367
|
|
|
} |
368
|
|
|
|
369
|
|
|
/** |
370
|
|
|
* Set the user's display name |
371
|
|
|
* |
372
|
|
|
* @param string $name The user's new display name |
373
|
|
|
* |
374
|
|
|
* @return boolean true if the user's display name was changed, false otherwise |
375
|
|
|
*/ |
376
|
|
|
public function setDisplayName($name) |
377
|
|
|
{ |
378
|
|
|
return $this->setNickName($name); |
379
|
|
|
} |
380
|
|
|
|
381
|
|
|
/** |
382
|
|
|
* Set the user's given (first) name |
383
|
|
|
* |
384
|
|
|
* @param string $name The user's new given name |
385
|
|
|
* |
386
|
|
|
* @return boolean true if the user's given name was changed, false otherwise |
387
|
|
|
*/ |
388
|
|
|
public function setGivenName($name) |
389
|
|
|
{ |
390
|
|
|
return $this->setUid($name); |
391
|
|
|
} |
392
|
|
|
|
393
|
|
|
/** |
394
|
|
|
* Set the user's email address |
395
|
|
|
* |
396
|
|
|
* @param string $email The user's new email address |
397
|
|
|
* |
398
|
|
|
* @return boolean true if the user's email address was changed, false otherwise |
399
|
|
|
* |
400
|
|
|
* @SuppressWarnings("UnusedFormalParameter") |
401
|
|
|
*/ |
402
|
|
|
public function setEmail($email) |
403
|
|
|
{ |
404
|
|
|
return false; |
405
|
|
|
} |
406
|
|
|
|
407
|
|
|
/** |
408
|
|
|
* Set the user's user ID or user name |
409
|
|
|
* |
410
|
|
|
* @param string $uid The user's new user ID |
411
|
|
|
* |
412
|
|
|
* @return boolean true if the user's ID was changed, false otherwise |
413
|
|
|
* |
414
|
|
|
* @SuppressWarnings("UnusedFormalParameter") |
415
|
|
|
*/ |
416
|
|
|
public function setUid($uid) |
417
|
|
|
{ |
418
|
|
|
return false; |
419
|
|
|
} |
420
|
|
|
|
421
|
|
|
/** |
422
|
|
|
* Set the user's photo |
423
|
|
|
* |
424
|
|
|
* @param string $photo The user's new photo as a binary string |
425
|
|
|
* |
426
|
|
|
* @return boolean true if the user's photo was changed, false otherwise |
427
|
|
|
* |
428
|
|
|
* @SuppressWarnings("UnusedFormalParameter") |
429
|
|
|
*/ |
430
|
|
|
public function setPhoto($photo) |
431
|
|
|
{ |
432
|
|
|
return false; |
433
|
|
|
} |
434
|
|
|
|
435
|
|
|
/** |
436
|
|
|
* Set the user's phone number |
437
|
|
|
* |
438
|
|
|
* @param string $phone The user's new phonew number |
439
|
|
|
* |
440
|
|
|
* @return boolean true if the user's phone number was changed, false otherwise |
441
|
|
|
* |
442
|
|
|
* @SuppressWarnings("UnusedFormalParameter") |
443
|
|
|
*/ |
444
|
|
|
public function setPhoneNumber($phone) |
445
|
|
|
{ |
446
|
|
|
return false; |
447
|
|
|
} |
448
|
|
|
|
449
|
|
|
/** |
450
|
|
|
* Set the user's organization |
451
|
|
|
* |
452
|
|
|
* @param string $org The user's new organization |
453
|
|
|
* |
454
|
|
|
* @return boolean true if the user's organization was changed, false otherwise |
455
|
|
|
* |
456
|
|
|
* @SuppressWarnings("UnusedFormalParameter") |
457
|
|
|
*/ |
458
|
|
|
public function setOrganization($org) |
459
|
|
|
{ |
460
|
|
|
return false; |
461
|
|
|
} |
462
|
|
|
|
463
|
|
|
/** |
464
|
|
|
* Set the user's titles |
465
|
|
|
* |
466
|
|
|
* @param string $titles The user's new titles |
467
|
|
|
* |
468
|
|
|
* @return boolean true if the user's titles were changed, false otherwise |
469
|
|
|
* |
470
|
|
|
* @SuppressWarnings("UnusedFormalParameter") |
471
|
|
|
*/ |
472
|
|
|
public function setTitles($titles) |
473
|
|
|
{ |
474
|
|
|
return false; |
475
|
|
|
} |
476
|
|
|
|
477
|
|
|
/** |
478
|
|
|
* Set the user's state |
479
|
|
|
* |
480
|
|
|
* @param string $state The user's new state |
481
|
|
|
* |
482
|
|
|
* @return boolean true if the user's state was changed, false otherwise |
483
|
|
|
* |
484
|
|
|
* @SuppressWarnings("UnusedFormalParameter") |
485
|
|
|
*/ |
486
|
|
|
public function setState($state) |
487
|
|
|
{ |
488
|
|
|
return false; |
489
|
|
|
} |
490
|
|
|
|
491
|
|
|
/** |
492
|
|
|
* Set the user's city |
493
|
|
|
* |
494
|
|
|
* @param string $city The user's new city |
495
|
|
|
* |
496
|
|
|
* @return boolean true if the user's city was changed, false otherwise |
497
|
|
|
* |
498
|
|
|
* @SuppressWarnings("UnusedFormalParameter") |
499
|
|
|
*/ |
500
|
|
|
public function setCity($city) |
501
|
|
|
{ |
502
|
|
|
return false; |
503
|
|
|
} |
504
|
|
|
|
505
|
|
|
/** |
506
|
|
|
* Set the user's last name |
507
|
|
|
* |
508
|
|
|
* @param string $sn The user's new last name |
509
|
|
|
* |
510
|
|
|
* @return boolean true if the user's last name was changed, false otherwise |
511
|
|
|
* |
512
|
|
|
* @SuppressWarnings("UnusedFormalParameter") |
513
|
|
|
*/ |
514
|
|
|
public function setLastName($sn) |
515
|
|
|
{ |
516
|
|
|
return false; |
517
|
|
|
} |
518
|
|
|
|
519
|
|
|
/** |
520
|
|
|
* Set the user's nick name |
521
|
|
|
* |
522
|
|
|
* @param string $displayName The user's new nick name |
523
|
|
|
* |
524
|
|
|
* @return boolean true if the user's nick name was changed, false otherwise |
525
|
|
|
*/ |
526
|
|
|
public function setNickName($displayName) |
527
|
|
|
{ |
528
|
|
|
return $this->setUid($displayName); |
529
|
|
|
} |
530
|
|
|
|
531
|
|
|
/** |
532
|
|
|
* Set the user's mailing address |
533
|
|
|
* |
534
|
|
|
* @param string $address The user's new mailing address |
535
|
|
|
* |
536
|
|
|
* @return boolean true if the user's mailing address was changed, false otherwise |
537
|
|
|
* |
538
|
|
|
* @SuppressWarnings("UnusedFormalParameter") |
539
|
|
|
*/ |
540
|
|
|
public function setAddress($address) |
541
|
|
|
{ |
542
|
|
|
return false; |
543
|
|
|
} |
544
|
|
|
|
545
|
|
|
/** |
546
|
|
|
* Set the user's postal or zip code |
547
|
|
|
* |
548
|
|
|
* @param string $postalcode The user's new postal code |
549
|
|
|
* |
550
|
|
|
* @return boolean true if the user's postal code was changed, false otherwise |
551
|
|
|
* |
552
|
|
|
* @SuppressWarnings("UnusedFormalParameter") |
553
|
|
|
*/ |
554
|
|
|
public function setPostalCode($postalcode) |
555
|
|
|
{ |
556
|
|
|
return false; |
557
|
|
|
} |
558
|
|
|
|
559
|
|
|
/** |
560
|
|
|
* Set the user's country |
561
|
|
|
* |
562
|
|
|
* @param string $country The user's new country |
563
|
|
|
* |
564
|
|
|
* @return boolean true if the user's country was changed, false otherwise |
565
|
|
|
* |
566
|
|
|
* @SuppressWarnings("UnusedFormalParameter") |
567
|
|
|
*/ |
568
|
|
|
public function setCountry($country) |
569
|
|
|
{ |
570
|
|
|
return false; |
571
|
|
|
} |
572
|
|
|
|
573
|
|
|
/** |
574
|
|
|
* Set the user's organizations |
575
|
|
|
* |
576
|
|
|
* @param string $ous The user's new organizations |
577
|
|
|
* |
578
|
|
|
* @return boolean true if the user's organizations was changed, false otherwise |
579
|
|
|
* |
580
|
|
|
* @SuppressWarnings("UnusedFormalParameter") |
581
|
|
|
*/ |
582
|
|
|
public function setOrganizationUnits($ous) |
583
|
|
|
{ |
584
|
|
|
return false; |
585
|
|
|
} |
586
|
|
|
|
587
|
|
|
/** |
588
|
|
|
* Allow write for the user |
589
|
|
|
*/ |
590
|
|
|
protected function enableReadWrite() |
591
|
|
|
{ |
592
|
|
|
//Make sure we are bound in write mode |
593
|
|
|
$auth = \AuthProvider::getInstance(); |
594
|
|
|
$ldap = $auth->getMethodByName('Auth\LDAPAuthenticator'); |
595
|
|
|
if($ldap !== false) |
596
|
|
|
{ |
597
|
|
|
$ldap->get_and_bind_server(true); |
598
|
|
|
} |
599
|
|
|
} |
600
|
|
|
|
601
|
|
|
/** |
602
|
|
|
* Update the user password if required |
603
|
|
|
*/ |
604
|
|
|
private function editUserPassword($data) |
605
|
|
|
{ |
606
|
|
|
if(isset($data->password)) |
607
|
|
|
{ |
608
|
|
|
if(isset($data->oldpass)) |
609
|
|
|
{ |
610
|
|
|
$this->change_pass($data->oldpass, $data->password); |
611
|
|
|
unset($data->oldpass); |
612
|
|
|
} |
613
|
|
|
else if(isset($data->hash)) |
614
|
|
|
{ |
615
|
|
|
$this->change_pass($data->hash, $data->password, true); |
616
|
|
|
unset($data->hash); |
617
|
|
|
} |
618
|
|
|
unset($data->password); |
619
|
|
|
} |
620
|
|
|
} |
621
|
|
|
|
622
|
|
|
private function editNames($data) |
623
|
|
|
{ |
624
|
|
|
if(isset($data->displayName)) |
625
|
|
|
{ |
626
|
|
|
$this->setDisplayName($data->displayName); |
627
|
|
|
unset($data->displayName); |
628
|
|
|
} |
629
|
|
|
if(isset($data->givenName)) |
630
|
|
|
{ |
631
|
|
|
$this->setGivenName($data->givenName); |
632
|
|
|
unset($data->givenName); |
633
|
|
|
} |
634
|
|
|
if(isset($data->sn)) |
635
|
|
|
{ |
636
|
|
|
$this->setLastName($data->sn); |
637
|
|
|
unset($data->sn); |
638
|
|
|
} |
639
|
|
|
if(isset($data->cn)) |
640
|
|
|
{ |
641
|
|
|
$this->setNickName($data->cn); |
642
|
|
|
unset($data->cn); |
643
|
|
|
} |
644
|
|
|
} |
645
|
|
|
|
646
|
|
|
private function checkForUnsettableElements($data) |
647
|
|
|
{ |
648
|
|
|
if(isset($data->mail)) |
649
|
|
|
{ |
650
|
|
|
if($data->mail !== $this->getEmail()) |
651
|
|
|
{ |
652
|
|
|
throw new \Exception('Unable to change email!'); |
653
|
|
|
} |
654
|
|
|
unset($data->mail); |
655
|
|
|
} |
656
|
|
|
if(isset($data->uid)) |
657
|
|
|
{ |
658
|
|
|
if($data->uid !== $this->getUid()) |
659
|
|
|
{ |
660
|
|
|
throw new \Exception('Unable to change uid!'); |
661
|
|
|
} |
662
|
|
|
unset($data->uid); |
663
|
|
|
} |
664
|
|
|
} |
665
|
|
|
|
666
|
|
|
private function editAddressElements($data) |
667
|
|
|
{ |
668
|
|
|
if(isset($data->postalAddress)) |
669
|
|
|
{ |
670
|
|
|
$this->setAddress($data->postalAddress); |
671
|
|
|
unset($data->postalAddress); |
672
|
|
|
} |
673
|
|
|
if(isset($data->l)) |
674
|
|
|
{ |
675
|
|
|
$this->setCity($data->l); |
676
|
|
|
unset($data->l); |
677
|
|
|
} |
678
|
|
|
if(isset($data->st)) |
679
|
|
|
{ |
680
|
|
|
$this->setState($data->st); |
681
|
|
|
unset($data->st); |
682
|
|
|
} |
683
|
|
|
if(isset($data->postalCode)) |
684
|
|
|
{ |
685
|
|
|
$this->setPostalCode($data->postalCode); |
686
|
|
|
unset($data->postalCode); |
687
|
|
|
} |
688
|
|
|
if(isset($data->c)) |
689
|
|
|
{ |
690
|
|
|
$this->setCountry($data->c); |
691
|
|
|
unset($data->c); |
692
|
|
|
} |
693
|
|
|
} |
694
|
|
|
|
695
|
|
|
private function editOrganizationElements($data) |
696
|
|
|
{ |
697
|
|
|
if(isset($data->o)) |
698
|
|
|
{ |
699
|
|
|
$this->setOrganization($data->o); |
700
|
|
|
unset($data->o); |
701
|
|
|
} |
702
|
|
|
if(isset($data->title)) |
703
|
|
|
{ |
704
|
|
|
$this->setTitles($data->title); |
705
|
|
|
unset($data->title); |
706
|
|
|
} |
707
|
|
|
if(isset($data->ou)) |
708
|
|
|
{ |
709
|
|
|
$this->setOrganizationUnits($data->ou); |
710
|
|
|
unset($data->ou); |
711
|
|
|
} |
712
|
|
|
} |
713
|
|
|
|
714
|
|
|
/** |
715
|
|
|
* Modify the user given the provided data object |
716
|
|
|
* |
717
|
|
|
* @param stdClass $data The user's new data |
718
|
|
|
* |
719
|
|
|
* @return boolean true if the user's data was changed, false otherwise |
720
|
|
|
*/ |
721
|
|
|
public function editUser($data) |
722
|
|
|
{ |
723
|
|
|
$this->enableReadWrite(); |
724
|
|
|
|
725
|
|
|
$this->checkForUnsettableElements($data); |
726
|
|
|
$this->editUserPassword($data); |
727
|
|
|
$this->editNames($data); |
728
|
|
|
$this->editAddressElements($data); |
729
|
|
|
$this->editOrganizationElements($data); |
730
|
|
|
|
731
|
|
|
if(isset($data->jpegPhoto)) |
732
|
|
|
{ |
733
|
|
|
$this->setPhoto(base64_decode($data->jpegPhoto)); |
734
|
|
|
unset($data->jpegPhoto); |
735
|
|
|
} |
736
|
|
|
if(isset($data->mobile)) |
737
|
|
|
{ |
738
|
|
|
$this->setPhoneNumber($data->mobile); |
739
|
|
|
unset($data->mobile); |
740
|
|
|
} |
741
|
|
|
} |
742
|
|
|
|
743
|
|
|
/** |
744
|
|
|
* Obtain the user's password reset hash |
745
|
|
|
* |
746
|
|
|
* @return string|false A hash if available, false otherwise |
747
|
|
|
*/ |
748
|
|
|
public function getPasswordResetHash() |
749
|
|
|
{ |
750
|
|
|
return false; |
751
|
|
|
} |
752
|
|
|
|
753
|
|
|
/** |
754
|
|
|
* Serialize the user data into a format usable by the json_encode method |
755
|
|
|
* |
756
|
|
|
* @return array A simple keyed array representing the user |
757
|
|
|
*/ |
758
|
|
|
public function jsonSerialize() |
759
|
|
|
{ |
760
|
|
|
$user = array(); |
761
|
|
|
$user['displayName'] = $this->displayName; |
|
|
|
|
762
|
|
|
$user['givenName'] = $this->givenName; |
|
|
|
|
763
|
|
|
$user['jpegPhoto'] = base64_encode($this->getPhoto()); |
764
|
|
|
$user['mail'] = $this->getEmail(); |
765
|
|
|
$user['mobile'] = $this->getPhoneNumber(); |
766
|
|
|
$user['uid'] = $this->getUid(); |
767
|
|
|
$user['o'] = $this->getOrganization(); |
768
|
|
|
$user['title'] = $this->getTitles(); |
769
|
|
|
$user['titlenames'] = $this->getTitleNames(); |
770
|
|
|
$user['st'] = $this->getState(); |
771
|
|
|
$user['l'] = $this->getCity(); |
772
|
|
|
$user['sn'] = $this->getLastName(); |
773
|
|
|
$user['cn'] = $this->getNickName(); |
774
|
|
|
$user['postalAddress'] = $this->getAddress(); |
775
|
|
|
$user['postalCode'] = $this->getPostalCode(); |
776
|
|
|
$user['c'] = $this->getCountry(); |
777
|
|
|
$user['ou'] = $this->getOrganizationUnits(); |
778
|
|
|
$user['host'] = $this->getLoginProviders(); |
779
|
|
|
$user['class'] = get_class($this); |
780
|
|
|
return $user; |
781
|
|
|
} |
782
|
|
|
|
783
|
|
|
/** |
784
|
|
|
* Serialize the user data into a VCARD 2.1 format |
785
|
|
|
* |
786
|
|
|
* @return string The VCARD for the user |
787
|
|
|
*/ |
788
|
|
|
public function getVcard() |
789
|
|
|
{ |
790
|
|
|
$ret = "BEGIN:VCARD\nVERSION:2.1\n"; |
791
|
|
|
$ret .= 'N:'.$this->getLastName().';'.$this->givenName."\n"; |
|
|
|
|
792
|
|
|
$ret .= 'FN:'.$this->givenName."\n"; |
|
|
|
|
793
|
|
|
$titles = $this->getTitles(); |
794
|
|
|
if($titles !== false) |
795
|
|
|
{ |
796
|
|
|
$ret .= 'TITLE:'.implode(',', $titles)."\n"; |
797
|
|
|
} |
798
|
|
|
$ret .= "ORG: Austin Artistic Reconstruction\n"; |
799
|
|
|
$ret .= 'TEL;TYPE=MOBILE,VOICE:'.$this->getPhoneNumber()."\n"; |
800
|
|
|
$ret .= 'EMAIL;TYPE=PREF,INTERNET:'.$this->getEmail()."\n"; |
801
|
|
|
$ret .= "END:VCARD\n"; |
802
|
|
|
return $ret; |
803
|
|
|
} |
804
|
|
|
} |
805
|
|
|
/* vim: set tabstop=4 shiftwidth=4 expandtab: */ |
806
|
|
|
|
Since your code implements the magic setter
_set
, this function will be called for any write access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.