This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * CakeCMS Community |
||
4 | * |
||
5 | * This file is part of the of the simple cms based on CakePHP 3. |
||
6 | * For the full copyright and license information, please view the LICENSE |
||
7 | * file that was distributed with this source code. |
||
8 | * |
||
9 | * @package Community |
||
10 | * @license MIT |
||
11 | * @copyright MIT License http://www.opensource.org/licenses/mit-license.php |
||
12 | * @link https://github.com/CakeCMS/Community". |
||
13 | * @author Sergey Kalistratov <[email protected]> |
||
14 | */ |
||
15 | |||
16 | namespace Community\Controller\Admin; |
||
17 | |||
18 | use Community\Token; |
||
19 | use JBZoo\Utils\Filter; |
||
20 | use Community\Model\Entity\User; |
||
21 | use Community\Model\Table\UsersTable; |
||
22 | use Community\Controller\Component\AuthComponent; |
||
23 | use Cake\ORM\Exception\RolledbackTransactionException; |
||
24 | use Cake\Datasource\Exception\RecordNotFoundException; |
||
25 | use Cake\Datasource\Exception\InvalidPrimaryKeyException; |
||
26 | |||
27 | /** |
||
28 | * Class UsersController |
||
29 | * |
||
30 | * @package Community\Controller\Admin |
||
31 | * |
||
32 | * @property AuthComponent $Auth |
||
33 | * @property UsersTable $Users |
||
34 | */ |
||
35 | class UsersController extends AppController |
||
36 | { |
||
37 | |||
38 | /** |
||
39 | * Add action. |
||
40 | * |
||
41 | * @return \Cake\Http\Response|null |
||
42 | * |
||
43 | * @throws \Aura\Intl\Exception |
||
44 | * @throws \Cake\ORM\Exception\RolledbackTransactionException |
||
45 | */ |
||
46 | public function add() |
||
47 | { |
||
48 | $user = $this->Users->newEntity(); |
||
49 | if ($this->request->is('post')) { |
||
50 | $user = $this->Users->patchEntity($user, $this->request->getData()); |
||
0 ignored issues
–
show
|
|||
51 | if (Filter::bool($user->get('notify'))) { |
||
52 | $user->set('token', Token::generate()); |
||
53 | } |
||
54 | |||
55 | $result = $this->Users->save($user); |
||
56 | if ($result) { |
||
57 | $this->Flash->success(__d('community', 'The user {0} has been saved.', sprintf( |
||
58 | '<strong>«%s»</strong>', |
||
59 | $result->get('login') |
||
60 | ))); |
||
61 | |||
62 | return $this->App->redirect(['apply' => ['action' => 'edit', $result->id]]); |
||
0 ignored issues
–
show
Accessing
id on the interface Cake\Datasource\EntityInterface suggest that you code against a concrete implementation. How about adding an instanceof check?
If you access a property on an interface, you most likely code against a concrete implementation of the interface. Available Fixes
![]() |
|||
63 | } else { |
||
64 | $this->Flash->error(__d('community', 'User could not be updated. Please, try again.')); |
||
65 | } |
||
66 | } |
||
67 | |||
68 | $groups = $this->Users->Groups->getTreeList(); |
||
69 | |||
70 | $this |
||
71 | ->set(compact('user', 'groups')) |
||
72 | ->set('page_title', __d('community', 'Profiles: Add new user')); |
||
73 | } |
||
74 | |||
75 | /** |
||
76 | * Change user password action. |
||
77 | * |
||
78 | * @param null|int $id User id. |
||
79 | * @return \Cake\Http\Response|null |
||
80 | * |
||
81 | * @throws \Aura\Intl\Exception |
||
82 | */ |
||
83 | public function changePassword($id = null) |
||
84 | { |
||
85 | $user = $this->Users->get($id, ['contain' => []]); |
||
86 | $user->set('password', null); |
||
87 | |||
88 | View Code Duplication | if ($this->request->is(['patch', 'post', 'put'])) { |
|
0 ignored issues
–
show
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. ![]() |
|||
89 | $user = $this->Users->patchEntity($user, $this->request->getData()); |
||
0 ignored issues
–
show
It seems like
$this->request->getData() targeting Cake\Http\ServerRequest::getData() can also be of type null or string ; however, Cake\ORM\Table::patchEntity() does only seem to accept array , maybe add an additional type check?
This check looks at variables that are passed out again to other methods. If the outgoing method call has stricter type requirements than the method itself, an issue is raised. An additional type check may prevent trouble. ![]() |
|||
90 | if ($result = $this->Users->save($user)) { |
||
91 | $this->Flash->success(__d('community', 'Password has been updated.')); |
||
92 | return $this->App->redirect(['apply' => ['action' => 'edit', $result->id]]); |
||
0 ignored issues
–
show
Accessing
id on the interface Cake\Datasource\EntityInterface suggest that you code against a concrete implementation. How about adding an instanceof check?
If you access a property on an interface, you most likely code against a concrete implementation of the interface. Available Fixes
![]() |
|||
93 | } else { |
||
94 | $this->Flash->error(__d('community', 'Password could not be updated. Please, try again.')); |
||
95 | } |
||
96 | } |
||
97 | |||
98 | $this |
||
99 | ->set(compact('user')) |
||
100 | ->set('page_title', __d('community', 'Profiles: {0} - change password', $user->name)); |
||
0 ignored issues
–
show
Accessing
name on the interface Cake\Datasource\EntityInterface suggest that you code against a concrete implementation. How about adding an instanceof check?
If you access a property on an interface, you most likely code against a concrete implementation of the interface. Available Fixes
![]() |
|||
101 | } |
||
102 | |||
103 | /** |
||
104 | * Edit action. |
||
105 | * |
||
106 | * @param null|int $id User id. |
||
107 | * @return \Cake\Http\Response|null |
||
108 | * |
||
109 | * @throws \Aura\Intl\Exception |
||
110 | * @throws RecordNotFoundException |
||
111 | * @throws InvalidPrimaryKeyException |
||
112 | * @throws RolledbackTransactionException |
||
113 | */ |
||
114 | public function edit($id = null) |
||
115 | { |
||
116 | /** @var User $user */ |
||
117 | $user = $this->Users->get($id); |
||
118 | $groups = $this->Users->Groups->getTreeList(); |
||
119 | |||
120 | View Code Duplication | if ($this->request->is(['patch', 'post', 'put'])) { |
|
0 ignored issues
–
show
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. ![]() |
|||
121 | $user = $this->Users->patchEntity($user, $this->request->getData()); |
||
0 ignored issues
–
show
It seems like
$this->request->getData() targeting Cake\Http\ServerRequest::getData() can also be of type null or string ; however, Cake\ORM\Table::patchEntity() does only seem to accept array , maybe add an additional type check?
This check looks at variables that are passed out again to other methods. If the outgoing method call has stricter type requirements than the method itself, an issue is raised. An additional type check may prevent trouble. ![]() |
|||
122 | if ($result = $this->Users->save($user)) { |
||
123 | $this->Flash->success(__d('community', 'The user {0} has been saved.', sprintf( |
||
124 | '<strong>«%s»</strong>', |
||
125 | $result->get('login') |
||
126 | ))); |
||
127 | return $this->App->redirect([ |
||
128 | 'apply' => ['action' => 'edit', $result->id] |
||
0 ignored issues
–
show
Accessing
id on the interface Cake\Datasource\EntityInterface suggest that you code against a concrete implementation. How about adding an instanceof check?
If you access a property on an interface, you most likely code against a concrete implementation of the interface. Available Fixes
![]() |
|||
129 | ]); |
||
130 | } else { |
||
131 | $this->Flash->error(__d('community', 'User could not be updated. Please, try again.')); |
||
132 | } |
||
133 | } |
||
134 | |||
135 | $this |
||
136 | ->set(compact('user', 'groups')) |
||
137 | ->set('page_title', __d('community', 'Profiles: Edit user - {0}', $user->name)); |
||
0 ignored issues
–
show
Accessing
name on the interface Cake\Datasource\EntityInterface suggest that you code against a concrete implementation. How about adding an instanceof check?
If you access a property on an interface, you most likely code against a concrete implementation of the interface. Available Fixes
![]() |
|||
138 | } |
||
139 | |||
140 | /** |
||
141 | * Index action. |
||
142 | * |
||
143 | * @return void |
||
144 | * |
||
145 | * @throws \Aura\Intl\Exception |
||
146 | * @throws \RuntimeException |
||
147 | */ |
||
148 | public function index() |
||
149 | { |
||
150 | $query = $this->Users |
||
151 | ->find('search', $this->Users->filterParams($this->request->getQueryParams())) |
||
152 | ->contain('Groups'); |
||
153 | |||
154 | $this |
||
155 | ->set('users', $this->paginate($query)) |
||
0 ignored issues
–
show
It seems like
$query defined by $this->Users->find('sear...()))->contain('Groups') on line 150 can also be of type array ; however, Cake\Controller\Controller::paginate() does only seem to accept object<Cake\ORM\Table>|s...ct<Cake\ORM\Query>|null , 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. ![]() |
|||
156 | ->set('page_title', __d('community', 'Profiles: User list')); |
||
157 | } |
||
158 | |||
159 | /** |
||
160 | * Initialization hook method. Implement this method to avoid having to overwrite the constructor and call parent. |
||
161 | * |
||
162 | * @return void |
||
163 | * |
||
164 | * @throws \JBZoo\Utils\Exception |
||
165 | * @throws \Cake\Core\Exception\Exception |
||
166 | */ |
||
167 | public function initialize() |
||
168 | { |
||
169 | parent::initialize(); |
||
170 | $this->Security->setConfig('unlockedFields', ['password', 'password_confirm']); |
||
171 | } |
||
172 | |||
173 | /** |
||
174 | * Login action. |
||
175 | * |
||
176 | * @return \Cake\Http\Response|null |
||
177 | * |
||
178 | * @throws \Aura\Intl\Exception |
||
179 | */ |
||
180 | View Code Duplication | public function login() |
|
0 ignored issues
–
show
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. ![]() |
|||
181 | { |
||
182 | $this->viewBuilder()->setLayout('login'); |
||
183 | if ($this->request->is('post')) { |
||
184 | $user = $this->Auth->identify(); |
||
185 | if ($user !== false) { |
||
186 | $this->Auth->setUser($user); |
||
0 ignored issues
–
show
It seems like
$user defined by $this->Auth->identify() on line 184 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. ![]() |
|||
187 | return $this->redirect($this->Auth->redirectUrl()); |
||
188 | } |
||
189 | |||
190 | $this->Flash->error(__d('community', 'Login or password is incorrect')); |
||
191 | } |
||
192 | |||
193 | $this->set('page_title', __d('community', 'Authorize profile')); |
||
194 | } |
||
195 | |||
196 | /** |
||
197 | * Logout action. |
||
198 | * |
||
199 | * @return \Cake\Http\Response|null |
||
200 | */ |
||
201 | public function logout() |
||
202 | { |
||
203 | return $this->redirect($this->Auth->logout()); |
||
204 | } |
||
205 | |||
206 | /** |
||
207 | * Process action. |
||
208 | * |
||
209 | * @return \Cake\Http\Response|null |
||
210 | * |
||
211 | * @throws \Aura\Intl\Exception |
||
212 | */ |
||
213 | public function process() |
||
214 | { |
||
215 | list($action, $ids) = $this->Process->getRequestVars($this->name); |
||
216 | return $this->Process->make($this->Users, $action, $ids); |
||
0 ignored issues
–
show
It seems like
$action defined by $this->Process->getRequestVars($this->name) on line 215 can also be of type array or null ; however, Core\Controller\Component\ProcessComponent::make() does only seem to accept string , 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. ![]() |
|||
217 | } |
||
218 | } |
||
219 |
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.