1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Modules\Entitizer\Controller { |
4
|
|
|
|
5
|
|
|
use Modules\Auth, Modules\Entitizer, Utils\Validate, Str; |
6
|
|
|
|
7
|
|
|
class User { |
8
|
|
|
|
9
|
|
|
private $user = null; |
10
|
|
|
|
11
|
|
|
# Constructor |
12
|
|
|
|
13
|
|
|
public function __construct(Entitizer\Entity\User $user) { |
14
|
|
|
|
15
|
|
|
$this->user = $user; |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
# Invoker |
19
|
|
|
|
20
|
|
|
public function __invoke(array $post) { |
21
|
|
|
|
22
|
|
|
# Declare variables |
23
|
|
|
|
24
|
|
|
$name = ''; $email = ''; $rank = ''; $first_name = ''; $last_name = ''; $sex = ''; |
25
|
|
|
|
26
|
|
|
$city = ''; $country = ''; $timezone = ''; $password = ''; $password_retype = ''; |
27
|
|
|
|
28
|
|
|
# Extract post array |
29
|
|
|
|
30
|
|
|
extract($post); |
31
|
|
|
|
32
|
|
|
# Validate name & email |
33
|
|
|
|
34
|
|
|
if (false === ($name = Validate::userName($name))) return 'USER_ERROR_NAME_INVALID'; |
35
|
|
|
|
36
|
|
|
if (false === ($email = Validate::userEmail($email))) return 'USER_ERROR_EMAIL_INVALID'; |
37
|
|
|
|
38
|
|
|
# Validate password |
39
|
|
|
|
40
|
|
|
if ((0 === $this->user->id) || ('' !== $password)) { |
|
|
|
|
41
|
|
|
|
42
|
|
|
if (false === ($password = Validate::userPassword($password))) return 'USER_ERROR_PASSWORD_INVALID'; |
43
|
|
|
|
44
|
|
|
if (0 !== strcmp($password, $password_retype)) return 'USER_ERROR_PASSWORD_MISMATCH'; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
# Check name exists |
48
|
|
|
|
49
|
|
|
if (false === ($check_name = $this->user->check('name', $name))) return 'USER_ERROR_MODIFY'; |
50
|
|
|
|
51
|
|
|
if ($check_name === 1) return 'USER_ERROR_NAME_DUPLICATE'; |
52
|
|
|
|
53
|
|
|
# Check email exists |
54
|
|
|
|
55
|
|
|
if (false === ($check_email = $this->user->check('email', $email))) return 'USER_ERROR_MODIFY'; |
56
|
|
|
|
57
|
|
|
if ($check_email === 1) return 'USER_ERROR_EMAIL_DUPLICATE'; |
58
|
|
|
|
59
|
|
|
# Modify user |
60
|
|
|
|
61
|
|
|
$data = []; |
62
|
|
|
|
63
|
|
|
$data['name'] = $name; |
64
|
|
|
$data['email'] = $email; |
65
|
|
|
$data['rank'] = $rank; |
66
|
|
|
$data['first_name'] = $first_name; |
67
|
|
|
$data['last_name'] = $last_name; |
68
|
|
|
$data['sex'] = $sex; |
69
|
|
|
$data['city'] = $city; |
70
|
|
|
$data['country'] = $country; |
71
|
|
|
$data['timezone'] = $timezone; |
72
|
|
|
|
73
|
|
|
if ((0 === $this->user->id) || ('' !== $password)) { |
|
|
|
|
74
|
|
|
|
75
|
|
|
$data['auth_key'] = ($auth_key = Str::random(40)); |
76
|
|
|
$data['password'] = Str::encode($auth_key, $password); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
if (0 === $this->user->id) { |
|
|
|
|
80
|
|
|
|
81
|
|
|
$data['time_registered'] = REQUEST_TIME; |
82
|
|
|
$data['time_logged'] = REQUEST_TIME; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
$modifier = ((0 === $this->user->id) ? 'create' : 'edit'); |
|
|
|
|
86
|
|
|
|
87
|
|
|
if (!$this->user->$modifier($data)) return 'USER_ERROR_MODIFY'; |
88
|
|
|
|
89
|
|
|
# ------------------------ |
90
|
|
|
|
91
|
|
|
return true; |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
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.