Completed
Pull Request — master (#178)
by Fèvre
02:40
created

UsersController::premium()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 15

Duplication

Lines 25
Ratio 100 %

Importance

Changes 0
Metric Value
dl 25
loc 25
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 15
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
                        //Write in the session the virtual field.
105
                        $this->request->session()->write('Auth.User.premium', $user->premium);
106
107
                        //Cookies.
108
                        $this->Cookie->configKey('CookieAuth', [
109
                            'expires' => '+1 year',
110
                            'httpOnly' => true
111
                        ]);
112
                        $this->Cookie->write('CookieAuth', [
113
                            'username' => $this->request->data('username'),
114
                            'password' => $this->request->data('password')
115
                        ]);
116
117
                        //Badge Event.
118
                        $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...
119
120
                        $user = new Event('Model.Users.register', $this, [
121
                            'user' => $user
122
                        ]);
123
                        $this->eventManager()->dispatch($user);
124
125
                        $url = $this->Auth->redirectUrl();
126 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...
127
                            $url = ['controller' => 'pages', 'action' => 'home'];
128
                        }
129
130
                        return $this->redirect($url);
131
                    }
132
133
                    $this->Flash->error(__("Your username or password doesn't match."));
134
135
                    break;
136
137
                case "register":
138
                    $userRegister->register_ip = $this->request->clientIp();
139
                    $userRegister->last_login_ip = $this->request->clientIp();
140
                    $userRegister->last_login = new Time();
141
142
                    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...
143
                        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...
144
                            $user = $this->Auth->identify();
145
146
                            if ($user) {
147
                                $this->Auth->setUser($user);
0 ignored issues
show
Bug introduced by
It seems like $user defined by $this->Auth->identify() on line 144 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...
148
                            }
149
150
                            $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...
151
152
                            //Statistics Event.
153
                            $this->eventManager()->attach(new Statistics());
0 ignored issues
show
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...
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...
154
                            $stats = new Event('Model.Users.register', $this);
155
                            $this->eventManager()->dispatch($stats);
156
157
                            //Notification Events.
158
                            $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...
159
                            $event = new Event('Model.Notifications.new', $this, [
160
                                'user_id' => $user->id,
161
                                'type' => 'bot'
162
                            ]);
163
                            $this->eventManager()->dispatch($event);
164
165
                            $viewVars = [
166
                                'user' => $user,
167
                                'name' => $user->full_name
168
                            ];
169
170
                            $email = new Email();
171
                            $email->profile('default')
172
                                ->template('register', 'default')
173
                                ->emailFormat('html')
174
                                ->from(['[email protected]' => __d('mail', 'Welcome on {0} !', \Cake\Core\Configure::read('Site.name'))])
175
                                ->to($user->email)
176
                                ->subject(__d('mail', 'Welcome on {0} !', \Cake\Core\Configure::read('Site.name')))
177
                                ->viewVars($viewVars)
178
                                ->send();
179
180
                            $this->Flash->success(__("Your account has been created successfully !"));
181
182
                            $url = $this->Auth->redirectUrl();
183 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...
184
                                $url = ['controller' => 'pages', 'action' => 'home'];
185
                            }
186
187
                            return $this->redirect($url);
188
                        }
189
190
                        $this->Flash->error(__("Please, correct your mistake."));
191
                    } else {
192
                        $this->Flash->error(__("Please, correct your Captcha."));
193
                    }
194
195
                    break;
196
            }
197
        } else {
198
            //Save the referer URL before the user send the login/register request else it will delete the referer.
199
            $this->request->session()->write('Auth.redirect', $this->referer());
200
        }
201
202
        if ($this->Auth->user()) {
203
            return $this->redirect($this->Auth->redirectUrl());
204
        }
205
206
        $this->set(compact('userRegister'));
207
    }
208
209
    /**
210
     * Logout an user.
211
     *
212
     * @return \Cake\Network\Response
213
     */
214
    public function logout()
215
    {
216
        return $this->redirect($this->Auth->logout());
217
    }
218
219
    /**
220
     * Page to configure our account.
221
     *
222
     * @return void
223
     */
224
    public function account()
225
    {
226
        $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...
227
228
        if ($this->request->is('put')) {
229
            $user->accessible('avatar_file', true);
230
            $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...
231
232
            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...
233
                $this->request->session()->write('Auth.User.avatar', $user->avatar);
234
                $this->Flash->success(__("Your information has been updated !"));
235
            }
236
        }
237
238
        $this->set(compact('user'));
239
    }
240
241
    /**
242
     * Page to configure our settings.
243
     *
244
     * @return \Cake\Network\Response|void
245
     */
246
    public function settings()
247
    {
248
        $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...
249
250
        $oldEmail = $user->email;
251
252
        if ($this->request->is('put')) {
253
            $method = ($this->request->data['method']) ? $this->request->data['method'] : false;
254
255
            switch ($method) {
256
                case "email":
257
                    if (!isset($this->request->data['email'])) {
258
                        $this->set(compact('user', 'oldEmail'));
259
260
                        return $this->redirect(['action' => 'settings']);
261
                    }
262
263
                    $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...
264
265
                    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...
266
                        $oldEmail = $this->request->data['email'];
267
268
                        $this->Flash->success(__("Your E-mail has been changed !"));
269
                    }
270
                    break;
271
272
                case "password":
273
                    $data = $this->request->data;
274
                    if (!isset($data['old_password']) || !isset($data['password']) || !isset($data['password_confirm'])) {
275
                        $this->set(compact('user', 'oldEmail'));
276
277
                        return $this->Flash->error(__("Please, complete all fields !"));
278
                    }
279
280
                    if (!(new DefaultPasswordHasher)->check($data['old_password'], $user->password)) {
281
                        $this->set(compact('user', 'oldEmail'));
282
283
                        return $this->Flash->error(__("Your old password don't match !"));
284
                    }
285
286
                    $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...
287
                    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...
288
                        $this->Flash->success(__("Your password has been changed !"));
289
                    }
290
                    break;
291
            }
292
        }
293
294
        $this->set(compact('user', 'oldEmail'));
295
    }
296
297
    /**
298
     * View a profile page of an user.
299
     *
300
     * @return \Cake\Network\Response|void
301
     */
302
    public function profile()
303
    {
304
        $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...
305
            ->find()
306
            ->where([
307
                'Users.id' => $this->request->id
308
            ])
309
            ->contain([
310
                'Groups' => function ($q) {
311
                    return $q->select(['id', 'name', 'css', 'is_staff', 'is_member']);
312
                },
313
                'BlogArticles' => function ($q) {
314
                    return $q
315
                        ->limit(Configure::read('User.Profile.max_blog_articles'))
316
                        ->order(['BlogArticles.created' => 'DESC']);
317
                },
318
                'BlogArticlesComments' => function ($q) {
319
                    return $q
320
                        ->limit(Configure::read('User.Profile.max_blog_comments'))
321
                        ->contain([
322
                            'BlogArticles' => function ($q) {
323
                                return $q->select(['id', 'title', 'slug']);
324
                            }
325
                        ])
326
                        ->order(['BlogArticlesComments.created' => 'DESC']);
327
                },
328
                'BadgesUsers' => function ($q) {
329
                    return $q
330
                        ->contain([
331
                            'Badges' => function ($q) {
332
                                return $q
333
                                    ->select([
334
                                        'name',
335
                                        'picture'
336
                                    ]);
337
                            }
338
                        ])
339
                        ->order([
340
                            'BadgesUsers.id' => 'DESC'
341
                        ]);
342
                }
343
            ])
344
            ->map(function ($user) {
345
                $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...
346
                $user->background_profile = UsersUtility::getProfileBackground();
347
348
                return $user;
349
            })
350
            ->first();
351
352 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...
353
            $this->Flash->error(__('This user doesn\'t exist or has been deleted.'));
354
355
            return $this->redirect(['controller' => 'pages', 'action' => 'home']);
356
        }
357
358
        $this->set(compact('user'));
359
    }
360
361
    /**
362
     * Delete an user with all his comments, articles and likes.
363
     *
364
     * @return \Cake\Network\Response
365
     */
366
    public function delete()
367
    {
368
        if (!$this->request->is('post')) {
369
            return $this->redirect(['action' => 'settings']);
370
        }
371
372
        $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...
373
374
        if (!(new DefaultPasswordHasher)->check($this->request->data['password'], $user->password)) {
375
            $this->Flash->error(__("Your password doesn't match !"));
376
377
            return $this->redirect(['action' => 'settings']);
378
        }
379
380
        $user->is_deleted = true;
381
382
        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...
383
            $this->Flash->success(__("Your account has been deleted successfully ! Thanks for your visit !"));
384
385
            return $this->redirect($this->Auth->logout());
386
        }
387
388
        $this->Flash->error(__("Unable to delete your account, please try again."));
389
390
        return $this->redirect(['action' => 'settings']);
391
    }
392
393
    /**
394
     * Display all premium transactions related to the user.
395
     *
396
     * @return void
397
     */
398 View Code Duplication
    public function premium()
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...
399
    {
400
        $this->loadModel('PremiumTransactions');
401
402
        $this->paginate = [
403
            'maxLimit' => Configure::read('User.transaction_per_page')
404
        ];
405
406
        $transactions = $this->PremiumTransactions
0 ignored issues
show
Documentation introduced by
The property PremiumTransactions 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...
407
            ->find()
408
            ->contain([
409
                'PremiumOffers',
410
                'PremiumDiscounts'
411
            ])
412
            ->where([
413
                'PremiumTransactions.user_id' => $this->Auth->user('id')
414
            ])
415
            ->order([
416
                'PremiumTransactions.created' => 'desc'
417
            ]);
418
419
        $transactions = $this->paginate($transactions);
420
421
        $this->set(compact('transactions'));
422
    }
423
424
    /**
425
     * Display all notifications related to the user.
426
     *
427
     * @return void
428
     */
429 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...
430
    {
431
        $this->loadModel('Notifications');
432
433
        $this->paginate = [
434
            'maxLimit' => Configure::read('User.notifications_per_page')
435
        ];
436
437
        $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...
438
            ->find()
439
            ->where([
440
                'user_id' => $this->Auth->user('id')
441
            ])
442
            ->order([
443
                'is_read' => 'ASC',
444
                'created' => 'DESC'
445
            ])
446
            ->find('map', [
447
                'session' => $this->request->session()
448
            ]);
449
450
        $notifications = $this->paginate($notifications);
451
452
        $this->set(compact('notifications'));
453
    }
454
455
    /**
456
     * Display the form to reset the password.
457
     *
458
     * @return \Cake\Network\Response|void
459
     */
460
    public function forgotPassword()
461
    {
462
        if ($this->Auth->user()) {
463
            return $this->redirect(['controller' => 'pages', 'action' => 'home']);
464
        }
465
466
        $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...
467
468
        if ($this->request->is('post')) {
469
            $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...
470
                ->find()
471
                ->where([
472
                    'Users.email' => $this->request->data['email']
473
                ])
474
                ->first();
475
476
            if (is_null($user)) {
477
                $this->Flash->error(__("This E-mail doesn't exist or the account has been deleted."));
478
479
                $this->set(compact('user'));
480
481
                return;
482
            }
483
484
            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...
485
                $this->Flash->error(__("Please, correct your Captcha."));
486
487
                $this->set(compact('user'));
488
489
                return;
490
            }
491
492
            //Generate the unique code
493
            $code = md5(rand() . uniqid() . time());
494
495
            //Update the user's information
496
            $user->password_code = $code;
497
            $user->password_code_expire = new Time();
498
499
            $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...
500
501
            $viewVars = [
502
                'userId' => $user->id,
503
                'name' => $user->full_name,
504
                'username' => $user->username,
505
                'code' => $code
506
            ];
507
508
            $email = new Email();
509
            $email->profile('default')
510
                ->template('forgotPassword', 'default')
511
                ->emailFormat('html')
512
                ->from(['[email protected]' => __('Forgot your Password - Xeta')])
513
                ->to($user->email)
514
                ->subject(__('Forgot your Password - Xeta'))
515
                ->viewVars($viewVars)
516
                ->send();
517
518
            $this->Flash->success(__("An E-mail has been send to <strong>{0}</strong>. Please follow the instructions in the E-mail.", h($user->email)));
519
        }
520
521
        $this->set(compact('user'));
522
    }
523
524
    /**
525
     * Display the form to reset his password.
526
     *
527
     * @return \Cake\Network\Response|void
528
     */
529
    public function resetPassword()
530
    {
531
        if ($this->Auth->user()) {
532
            return $this->redirect(['controller' => 'pages', 'action' => 'home']);
533
        }
534
535
        //Prevent for empty code.
536
        if (empty(trim($this->request->code))) {
537
            $this->Flash->error(__("This code is not associated with this users or is incorrect."));
538
539
            return $this->redirect(['controller' => 'pages', 'action' => 'home']);
540
        }
541
542
        $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...
543
            ->find()
544
            ->where([
545
                'Users.password_code' => $this->request->code,
546
                'Users.id' => $this->request->id
547
            ])
548
            ->first();
549
550 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...
551
            $this->Flash->error(__("This code is not associated with this users or is incorrect."));
552
553
            return $this->redirect(['controller' => 'pages', 'action' => 'home']);
554
        }
555
556
        $expire = $user->password_code_expire->timestamp + (Configure::read('User.ResetPassword.expire_code') * 60);
557
558
        if ($expire < time()) {
559
            $this->Flash->error(__("This code is expired, please ask another E-mail code."));
560
561
            return $this->redirect(['action' => 'forgotPassword']);
562
        }
563
564
        if ($this->request->is(['post', 'put'])) {
565
            $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...
566
567
            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...
568
                $this->Flash->success(__("Your password has been changed !"));
569
570
                //Reset the code and the time.
571
                $user->password_code = '';
572
                $user->password_code_expire = new Time();
573
                $user->password_reset_count = $user->password_reset_count + 1;
574
                $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...
575
576
                return $this->redirect(['controller' => 'users', 'action' => 'login']);
577
            }
578
        }
579
580
        $this->set(compact('user'));
581
    }
582
}
583