1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @package Cadmium\System\Modules\Auth |
5
|
|
|
* @author Anton Romanov |
6
|
|
|
* @copyright Copyright (c) 2015-2017, Anton Romanov |
7
|
|
|
* @link http://cadmium-cms.com |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Modules\Auth\Controller { |
11
|
|
|
|
12
|
|
|
use Modules\Auth, Modules\Entitizer, Utils\Validate, Str; |
13
|
|
|
|
14
|
|
|
class Recover { |
15
|
|
|
|
16
|
|
|
private $user = null; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Constructor |
20
|
|
|
*/ |
21
|
|
|
|
22
|
|
|
public function __construct(Entitizer\Entity\User $user) { |
23
|
|
|
|
24
|
|
|
$this->user = $user; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Invoker |
29
|
|
|
* |
30
|
|
|
* @return true|string|array : true on success, otherwise an error code, or an array of type [$param_name, $error_code], |
31
|
|
|
* where $param_name is a name of param that has triggered the error, |
32
|
|
|
* and $error_code is a language phrase related to the error |
33
|
|
|
*/ |
34
|
|
|
|
35
|
|
|
public function __invoke(array $post) { |
36
|
|
|
|
37
|
|
|
# Declare variables |
38
|
|
|
|
39
|
|
|
$password_new = ''; $password_retype = ''; |
40
|
|
|
|
41
|
|
|
# Extract post array |
42
|
|
|
|
43
|
|
|
extract($post); |
44
|
|
|
|
45
|
|
|
# Validate values |
46
|
|
|
|
47
|
|
|
if (false === ($password_new = Validate::userPassword($password_new))) |
48
|
|
|
|
49
|
|
|
return ['password_new', 'USER_ERROR_PASSWORD_NEW_INVALID']; |
50
|
|
|
|
51
|
|
|
if (0 !== strcmp($password_new, $password_retype)) |
52
|
|
|
|
53
|
|
|
return ['password_retype', 'USER_ERROR_PASSWORD_MISMATCH']; |
54
|
|
|
|
55
|
|
|
# Encode password |
56
|
|
|
|
57
|
|
|
$auth_key = Str::random(40); $password = Str::encode($auth_key, $password_new); |
58
|
|
|
|
59
|
|
|
# Update user |
60
|
|
|
|
61
|
|
|
$data = ['auth_key' => $auth_key, 'password' => $password]; |
62
|
|
|
|
63
|
|
|
if (!$this->user->edit($data)) return 'USER_ERROR_AUTH_RECOVER'; |
64
|
|
|
|
65
|
|
|
# Remove secret |
66
|
|
|
|
67
|
|
|
Entitizer::get(TABLE_USERS_SECRETS, $this->user->id)->remove(); |
|
|
|
|
68
|
|
|
|
69
|
|
|
# ------------------------ |
70
|
|
|
|
71
|
|
|
return true; |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read 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.