Completed
Pull Request — master (#178)
by Fèvre
10:47 queued 04:57
created

UsersController::logout()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
namespace App\Controller;
3
4
use App\Event\Badges;
5
use App\Event\Notifications;
6
use App\Event\Statistics;
7
use App\Utility\Users as UsersUtility;
8
use Cake\Auth\DefaultPasswordHasher;
9
use Cake\Core\Configure;
10
use Cake\Event\Event;
11
use Cake\I18n\Time;
12
use Cake\Network\Email\Email;
13
14
class UsersController extends AppController
15
{
16
17
    /**
18
     * Initialize handle.
19
     *
20
     * @return void
21
     */
22
    public function initialize()
23
    {
24
        parent::initialize();
25
26
        $action = $this->request->action;
0 ignored issues
show
Bug introduced by
The property action does not seem to exist in Cake\Network\Request.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
27
28
        if ($action === 'login' || $action === 'forgotPassword') {
29
            $this->loadComponent('Recaptcha.Recaptcha');
30
        }
31
    }
32
33
    /**
34
     * BeforeFilter handle.
35
     *
36
     * @param Event $event The beforeFilter event that was fired.
37
     *
38
     * @return void
39
     */
40
    public function beforeFilter(Event $event)
41
    {
42
        parent::beforeFilter($event);
43
44
        $this->Auth->allow(['index', 'logout', 'profile', 'forgotPassword', 'resetPassword']);
45
    }
46
47
    /**
48
     * Display all Users.
49
     *
50
     * @return void
51
     */
52
    public function index()
53
    {
54
        $this->paginate = [
55
            'maxLimit' => Configure::read('User.user_per_page')
56
        ];
57
        $users = $this->Users
0 ignored issues
show
Documentation introduced by
The property Users does not exist on object<App\Controller\UsersController>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
58
            ->find()
59
            ->contain([
60
                'Groups'
61
            ])
62
            ->order([
63
                'Users.created' => 'desc'
64
            ]);
65
66
        $users = $this->paginate($users);
67
68
        $this->set(compact('users'));
69
    }
70
71
    /**
72
     * Login and register page.
73
     *
74
     * @return \Cake\Network\Response|void
75
     */
76
    public function login()
77
    {
78
        $userRegister = $this->Users->newEntity($this->request->data, ['validate' => 'create']);
0 ignored issues
show
Documentation introduced by
The property Users does not exist on object<App\Controller\UsersController>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
79
80
        if ($this->request->is('post')) {
81
            $method = ($this->request->data['method']) ? $this->request->data['method'] : false;
82
83
            switch ($method) {
84
                case "login":
85
                    $userLogin = $this->Auth->identify();
86
87
                    if ($userLogin) {
88
                        if ($userLogin['is_deleted'] == true) {
89
                            $this->Flash->error(__("This account has been deleted."));
90
91
                            break;
92
                        }
93
94
                        $this->Auth->setUser($userLogin);
0 ignored issues
show
Bug introduced by
It seems like $userLogin defined by $this->Auth->identify() on line 85 can also be of type boolean; however, Cake\Controller\Component\AuthComponent::setUser() does only seem to accept array|object<ArrayAccess>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
95
96
                        $user = $this->Users->newEntity($userLogin, ['accessibleFields' => ['id' => true]]);
0 ignored issues
show
Documentation introduced by
The property Users does not exist on object<App\Controller\UsersController>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
97
                        $user->isNew(false);
98
99
                        $user->last_login = new Time();
100
                        $user->last_login_ip = $this->request->clientIp();
101
102
                        $this->Users->save($user);
0 ignored issues
show
Documentation introduced by
The property Users does not exist on object<App\Controller\UsersController>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
103
104
                        //Cookies.
105
                        $this->Cookie->configKey('CookieAuth', [
106
                            'expires' => '+1 year',
107
                            'httpOnly' => true
108
                        ]);
109
                        $this->Cookie->write('CookieAuth', [
110
                            'username' => $this->request->data('username'),
111
                            'password' => $this->request->data('password')
112
                        ]);
113
114
                        //Badge Event.
115
                        $this->eventManager()->attach(new Badges($this));
0 ignored issues
show
Documentation introduced by
new \App\Event\Badges($this) is of type object<App\Event\Badges>, but the function expects a callable.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Deprecated Code introduced by
The method Cake\Event\EventManager::attach() has been deprecated with message: 3.0.0 Use on() instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
116
117
                        $user = new Event('Model.Users.register', $this, [
118
                            'user' => $user
119
                        ]);
120
                        $this->eventManager()->dispatch($user);
121
122
                        $url = $this->Auth->redirectUrl();
123 View Code Duplication
                        if (substr($this->Auth->redirectUrl(), -5) == 'login') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
124
                            $url = ['controller' => 'pages', 'action' => 'home'];
125
                        }
126
127
                        return $this->redirect($url);
128
                    }
129
130
                    $this->Flash->error(__("Your username or password doesn't match."));
131
132
                    break;
133
134
                case "register":
135
                    $userRegister->register_ip = $this->request->clientIp();
136
                    $userRegister->last_login_ip = $this->request->clientIp();
137
                    $userRegister->last_login = new Time();
138
139
                    if ($this->Recaptcha->verify()) {
0 ignored issues
show
Documentation introduced by
The property Recaptcha does not exist on object<App\Controller\UsersController>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
140
                        if ($this->Users->save($userRegister)) {
0 ignored issues
show
Documentation introduced by
The property Users does not exist on object<App\Controller\UsersController>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
141
                            $user = $this->Auth->identify();
142
143
                            if ($user) {
144
                                $this->Auth->setUser($user);
0 ignored issues
show
Bug introduced by
It seems like $user defined by $this->Auth->identify() on line 141 can also be of type boolean; however, Cake\Controller\Component\AuthComponent::setUser() does only seem to accept array|object<ArrayAccess>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
145
                            }
146
147
                            $user = $this->Users->get($user['id']);
0 ignored issues
show
Documentation introduced by
The property Users does not exist on object<App\Controller\UsersController>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
148
149
                            //Statistics Event.
150
                            $this->eventManager()->attach(new Statistics());
0 ignored issues
show
Documentation introduced by
new \App\Event\Statistics() is of type object<App\Event\Statistics>, but the function expects a callable.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Deprecated Code introduced by
The method Cake\Event\EventManager::attach() has been deprecated with message: 3.0.0 Use on() instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
151
                            $stats = new Event('Model.Users.register', $this);
152
                            $this->eventManager()->dispatch($stats);
153
154
                            //Notification Events.
155
                            $this->eventManager()->attach(new Notifications());
0 ignored issues
show
Documentation introduced by
new \App\Event\Notifications() is of type object<App\Event\Notifications>, but the function expects a callable.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Deprecated Code introduced by
The method Cake\Event\EventManager::attach() has been deprecated with message: 3.0.0 Use on() instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
156
                            $event = new Event('Model.Notifications.new', $this, [
157
                                'user_id' => $user->id,
158
                                'type' => 'bot'
159
                            ]);
160
                            $this->eventManager()->dispatch($event);
161
162
                            $viewVars = [
163
                                'user' => $user,
164
                                'name' => $user->full_name
165
                            ];
166
167
                            $email = new Email();
168
                            $email->profile('default')
169
                                ->template('register', 'default')
170
                                ->emailFormat('html')
171
                                ->from(['[email protected]' => __d('mail', 'Welcome on {0} !', \Cake\Core\Configure::read('Site.name'))])
172
                                ->to($user->email)
173
                                ->subject(__d('mail', 'Welcome on {0} !', \Cake\Core\Configure::read('Site.name')))
174
                                ->viewVars($viewVars)
175
                                ->send();
176
177
                            $this->Flash->success(__("Your account has been created successfully !"));
178
179
                            $url = $this->Auth->redirectUrl();
180 View Code Duplication
                            if (substr($this->Auth->redirectUrl(), -5) == 'login') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
181
                                $url = ['controller' => 'pages', 'action' => 'home'];
182
                            }
183
184
                            return $this->redirect($url);
185
                        }
186
187
                        $this->Flash->error(__("Please, correct your mistake."));
188
                    } else {
189
                        $this->Flash->error(__("Please, correct your Captcha."));
190
                    }
191
192
                    break;
193
            }
194
        } else {
195
            //Save the referer URL before the user send the login/register request else it will delete the referer.
196
            $this->request->session()->write('Auth.redirect', $this->referer());
197
        }
198
199
        if ($this->Auth->user()) {
200
            return $this->redirect($this->Auth->redirectUrl());
201
        }
202
203
        $this->set(compact('userRegister'));
204
    }
205
206
    /**
207
     * Logout an user.
208
     *
209
     * @return \Cake\Network\Response
210
     */
211
    public function logout()
212
    {
213
        return $this->redirect($this->Auth->logout());
214
    }
215
216
    /**
217
     * Page to configure our account.
218
     *
219
     * @return void
220
     */
221
    public function account()
222
    {
223
        $user = $this->Users->get($this->Auth->user('id'));
0 ignored issues
show
Documentation introduced by
The property Users does not exist on object<App\Controller\UsersController>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
224
225
        if ($this->request->is('put')) {
226
            $user->accessible('avatar_file', true);
227
            $this->Users->patchEntity($user, $this->request->data(), ['validate' => 'account']);
0 ignored issues
show
Documentation introduced by
The property Users does not exist on object<App\Controller\UsersController>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
228
229
            if ($this->Users->save($user)) {
0 ignored issues
show
Documentation introduced by
The property Users does not exist on object<App\Controller\UsersController>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
230
                $this->request->session()->write('Auth.User.avatar', $user->avatar);
231
                $this->Flash->success(__("Your information has been updated !"));
232
            }
233
        }
234
235
        $this->set(compact('user'));
236
    }
237
238
    /**
239
     * Page to configure our settings.
240
     *
241
     * @return \Cake\Network\Response|void
242
     */
243
    public function settings()
244
    {
245
        $user = $this->Users->get($this->Auth->user('id'));
0 ignored issues
show
Documentation introduced by
The property Users does not exist on object<App\Controller\UsersController>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
246
247
        $oldEmail = $user->email;
248
249
        if ($this->request->is('put')) {
250
            $method = ($this->request->data['method']) ? $this->request->data['method'] : false;
251
252
            switch ($method) {
253
                case "email":
254
                    if (!isset($this->request->data['email'])) {
255
                        $this->set(compact('user', 'oldEmail'));
256
257
                        return $this->redirect(['action' => 'settings']);
258
                    }
259
260
                    $this->Users->patchEntity($user, $this->request->data(), ['validate' => 'settings']);
0 ignored issues
show
Documentation introduced by
The property Users does not exist on object<App\Controller\UsersController>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
261
262
                    if ($this->Users->save($user)) {
0 ignored issues
show
Documentation introduced by
The property Users does not exist on object<App\Controller\UsersController>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
263
                        $oldEmail = $this->request->data['email'];
264
265
                        $this->Flash->success(__("Your E-mail has been changed !"));
266
                    }
267
                    break;
268
269
                case "password":
270
                    $data = $this->request->data;
271
                    if (!isset($data['old_password']) || !isset($data['password']) || !isset($data['password_confirm'])) {
272
                        $this->set(compact('user', 'oldEmail'));
273
274
                        return $this->Flash->error(__("Please, complete all fields !"));
275
                    }
276
277
                    if (!(new DefaultPasswordHasher)->check($data['old_password'], $user->password)) {
278
                        $this->set(compact('user', 'oldEmail'));
279
280
                        return $this->Flash->error(__("Your old password don't match !"));
281
                    }
282
283
                    $this->Users->patchEntity($user, $this->request->data(), ['validate' => 'settings']);
0 ignored issues
show
Documentation introduced by
The property Users does not exist on object<App\Controller\UsersController>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
284
                    if ($this->Users->save($user)) {
0 ignored issues
show
Documentation introduced by
The property Users does not exist on object<App\Controller\UsersController>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
285
                        $this->Flash->success(__("Your password has been changed !"));
286
                    }
287
                    break;
288
            }
289
        }
290
291
        $this->set(compact('user', 'oldEmail'));
292
    }
293
294
    /**
295
     * View a profile page of an user.
296
     *
297
     * @return \Cake\Network\Response|void
298
     */
299
    public function profile()
300
    {
301
        $user = $this->Users
0 ignored issues
show
Documentation introduced by
The property Users does not exist on object<App\Controller\UsersController>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
302
            ->find()
303
            ->where([
304
                'Users.id' => $this->request->id
305
            ])
306
            ->contain([
307
                'Groups' => function ($q) {
308
                    return $q->select(['id', 'name', 'css', 'is_staff', 'is_member']);
309
                },
310
                'BlogArticles' => function ($q) {
311
                    return $q
312
                        ->limit(Configure::read('User.Profile.max_blog_articles'))
313
                        ->order(['BlogArticles.created' => 'DESC']);
314
                },
315
                'BlogArticlesComments' => function ($q) {
316
                    return $q
317
                        ->limit(Configure::read('User.Profile.max_blog_comments'))
318
                        ->contain([
319
                            'BlogArticles' => function ($q) {
320
                                return $q->select(['id', 'title']);
321
                            }
322
                        ])
323
                        ->order(['BlogArticlesComments.created' => 'DESC']);
324
                },
325
                'BadgesUsers' => function ($q) {
326
                    return $q
327
                        ->contain([
328
                            'Badges' => function ($q) {
329
                                return $q
330
                                    ->select([
331
                                        'name',
332
                                        'picture'
333
                                    ]);
334
                            }
335
                        ])
336
                        ->order([
337
                            'BadgesUsers.id' => 'DESC'
338
                        ]);
339
                }
340
            ])
341
            ->map(function ($user) {
342
                $user->online = $this->SessionsActivity->getOnlineStatus($user);
0 ignored issues
show
Documentation introduced by
The property SessionsActivity does not exist on object<App\Controller\UsersController>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
343
                $user->background_profile = UsersUtility::getProfileBackground();
344
345
                return $user;
346
            })
347
            ->first();
348
349 View Code Duplication
        if (is_null($user) || $user->is_deleted == true) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
350
            $this->Flash->error(__('This user doesn\'t exist or has been deleted.'));
351
352
            return $this->redirect(['controller' => 'pages', 'action' => 'home']);
353
        }
354
355
        $this->set(compact('user'));
356
    }
357
358
    /**
359
     * Delete an user with all his comments, articles and likes.
360
     *
361
     * @return \Cake\Network\Response
362
     */
363
    public function delete()
364
    {
365
        if (!$this->request->is('post')) {
366
            return $this->redirect(['action' => 'settings']);
367
        }
368
369
        $user = $this->Users->get($this->Auth->user('id'));
0 ignored issues
show
Documentation introduced by
The property Users does not exist on object<App\Controller\UsersController>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
370
371
        if (!(new DefaultPasswordHasher)->check($this->request->data['password'], $user->password)) {
372
            $this->Flash->error(__("Your password doesn't match !"));
373
374
            return $this->redirect(['action' => 'settings']);
375
        }
376
377
        $user->is_deleted = true;
378
379
        if ($this->Users->save($user)) {
0 ignored issues
show
Documentation introduced by
The property Users does not exist on object<App\Controller\UsersController>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
380
            $this->Flash->success(__("Your account has been deleted successfully ! Thanks for your visit !"));
381
382
            return $this->redirect($this->Auth->logout());
383
        }
384
385
        $this->Flash->error(__("Unable to delete your account, please try again."));
386
387
        return $this->redirect(['action' => 'settings']);
388
    }
389
390
    /**
391
     * Display all notifications related to the user.
392
     *
393
     * @return void
394
     */
395 View Code Duplication
    public function notifications()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
396
    {
397
        $this->loadModel('Notifications');
398
399
        $this->paginate = [
400
            'maxLimit' => Configure::read('User.notifications_per_page')
401
        ];
402
403
        $notifications = $this->Notifications
0 ignored issues
show
Documentation introduced by
The property Notifications does not exist on object<App\Controller\UsersController>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
404
            ->find()
405
            ->where([
406
                'user_id' => $this->Auth->user('id')
407
            ])
408
            ->order([
409
                'is_read' => 'ASC',
410
                'created' => 'DESC'
411
            ])
412
            ->find('map', [
413
                'session' => $this->request->session()
414
            ]);
415
416
        $notifications = $this->paginate($notifications);
417
418
        $this->set(compact('notifications'));
419
    }
420
421
    /**
422
     * Display the form to reset the password.
423
     *
424
     * @return \Cake\Network\Response|void
425
     */
426
    public function forgotPassword()
427
    {
428
        if ($this->Auth->user()) {
429
            return $this->redirect(['controller' => 'pages', 'action' => 'home']);
430
        }
431
432
        $user = $this->Users->newEntity($this->request->data);
0 ignored issues
show
Documentation introduced by
The property Users does not exist on object<App\Controller\UsersController>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
433
434
        if ($this->request->is('post')) {
435
            $user = $this->Users
0 ignored issues
show
Documentation introduced by
The property Users does not exist on object<App\Controller\UsersController>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
436
                ->find()
437
                ->where([
438
                    'Users.email' => $this->request->data['email']
439
                ])
440
                ->first();
441
442
            if (is_null($user)) {
443
                $this->Flash->error(__("This E-mail doesn't exist or the account has been deleted."));
444
445
                $this->set(compact('user'));
446
447
                return;
448
            }
449
450
            if (!$this->Recaptcha->verify()) {
0 ignored issues
show
Documentation introduced by
The property Recaptcha does not exist on object<App\Controller\UsersController>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
451
                $this->Flash->error(__("Please, correct your Captcha."));
452
453
                $this->set(compact('user'));
454
455
                return;
456
            }
457
458
            //Generate the unique code
459
            $code = md5(rand() . uniqid() . time());
460
461
            //Update the user's information
462
            $user->password_code = $code;
463
            $user->password_code_expire = new Time();
464
465
            $this->Users->save($user);
0 ignored issues
show
Documentation introduced by
The property Users does not exist on object<App\Controller\UsersController>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
466
467
            $viewVars = [
468
                'userId' => $user->id,
469
                'name' => $user->full_name,
470
                'username' => $user->username,
471
                'code' => $code
472
            ];
473
474
            $email = new Email();
475
            $email->profile('default')
476
                ->template('forgotPassword', 'default')
477
                ->emailFormat('html')
478
                ->from(['[email protected]' => __('Forgot your Password - Xeta')])
479
                ->to($user->email)
480
                ->subject(__('Forgot your Password - Xeta'))
481
                ->viewVars($viewVars)
482
                ->send();
483
484
            $this->Flash->success(__("An E-mail has been send to <strong>{0}</strong>. Please follow the instructions in the E-mail.", h($user->email)));
485
        }
486
487
        $this->set(compact('user'));
488
    }
489
490
    /**
491
     * Display the form to reset his password.
492
     *
493
     * @return \Cake\Network\Response|void
494
     */
495
    public function resetPassword()
496
    {
497
        if ($this->Auth->user()) {
498
            return $this->redirect(['controller' => 'pages', 'action' => 'home']);
499
        }
500
501
        //Prevent for empty code.
502
        if (empty(trim($this->request->code))) {
503
            $this->Flash->error(__("This code is not associated with this users or is incorrect."));
504
505
            return $this->redirect(['controller' => 'pages', 'action' => 'home']);
506
        }
507
508
        $user = $this->Users
0 ignored issues
show
Documentation introduced by
The property Users does not exist on object<App\Controller\UsersController>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
509
            ->find()
510
            ->where([
511
                'Users.password_code' => $this->request->code,
512
                'Users.id' => $this->request->id
513
            ])
514
            ->first();
515
516 View Code Duplication
        if (is_null($user)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
517
            $this->Flash->error(__("This code is not associated with this users or is incorrect."));
518
519
            return $this->redirect(['controller' => 'pages', 'action' => 'home']);
520
        }
521
522
        $expire = $user->password_code_expire->timestamp + (Configure::read('User.ResetPassword.expire_code') * 60);
523
524
        if ($expire < time()) {
525
            $this->Flash->error(__("This code is expired, please ask another E-mail code."));
526
527
            return $this->redirect(['action' => 'forgotPassword']);
528
        }
529
530
        if ($this->request->is(['post', 'put'])) {
531
            $this->Users->patchEntity($user, $this->request->data, ['validate' => 'resetpassword']);
0 ignored issues
show
Documentation introduced by
The property Users does not exist on object<App\Controller\UsersController>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
532
533
            if ($this->Users->save($user)) {
0 ignored issues
show
Documentation introduced by
The property Users does not exist on object<App\Controller\UsersController>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
534
                $this->Flash->success(__("Your password has been changed !"));
535
536
                //Reset the code and the time.
537
                $user->password_code = '';
538
                $user->password_code_expire = new Time();
539
                $user->password_reset_count = $user->password_reset_count + 1;
540
                $this->Users->save($user);
0 ignored issues
show
Documentation introduced by
The property Users does not exist on object<App\Controller\UsersController>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
541
542
                return $this->redirect(['controller' => 'users', 'action' => 'login']);
543
            }
544
        }
545
546
        $this->set(compact('user'));
547
    }
548
}
549