Completed
Push — master ( df8ec4...96358d )
by Nazar
04:25
created

users   A

Complexity

Total Complexity 28

Size/Duplication

Total Lines 345
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 9
Metric Value
wmc 28
lcom 1
cbo 9
dl 0
loc 345
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
C users_general() 0 86 7
A users_groups() 0 7 1
B users_mail() 0 92 4
A users_permissions() 0 7 1
A users_security() 0 57 1
D users_users() 0 94 14
1
<?php
2
/**
3
 * @package    CleverStyle CMS
4
 * @subpackage System module
5
 * @category   modules
6
 * @author     Nazar Mokrynskyi <[email protected]>
7
 * @copyright  Copyright (c) 2015, Nazar Mokrynskyi
8
 * @license    MIT License, see license.txt
9
 */
10
namespace cs\modules\System\admin\Controller;
11
use
12
	cs\Config,
13
	cs\Group,
14
	cs\Index,
15
	cs\Language,
16
	cs\Page,
17
	cs\Route,
18
	cs\User,
19
	h;
20
21
trait users {
22
	static function users_general () {
23
		$Config              = Config::instance();
24
		$Index               = Index::instance();
25
		$L                   = Language::instance();
26
		$Index->apply_button = true;
27
		$Index->content(
28
			static::vertical_table(
29
				static::core_input('session_expire', 'number', null, false, 1, false, $L->seconds),
30
				[
31
					h::info('sign_in_attempts_block_count'),
32
					h::{'input[is=cs-input-text][type=number]'}(
33
						[
34
							'name'     => 'core[sign_in_attempts_block_count]',
35
							'value'    => $Config->core['sign_in_attempts_block_count'],
36
							'min'      => 0,
37
							'onChange' => "if ($(this).val() == 0) { $('.cs-sign-in-attempts-block-count').hide(); } else { $('.cs-sign-in-attempts-block-count').show(); }"
38
						]
39
					)
40
				],
41
				[
42
					static::core_input('sign_in_attempts_block_time', 'number', null, false, 1, false, $L->seconds),
43
					[
44
						'style' => $Config->core['sign_in_attempts_block_count'] == 0 ? 'display: none;' : '',
45
						'class' => 'cs-sign-in-attempts-block-count'
46
					]
47
				],
48
				static::core_input('remember_user_ip', 'radio'),
49
				static::core_input('password_min_length', 'number', null, false, 4),
50
				static::core_input('password_min_strength', 'number', null, false, 0, 7),
51
				[
52
					h::info('allow_user_registration'),
53
					h::radio(
54
						[
55
							'name'     => 'core[allow_user_registration]',
56
							'checked'  => $Config->core['allow_user_registration'],
57
							'value'    => [0, 1],
58
							'in'       => [$L->off, $L->on],
59
							'onchange' => [
60
								"$('.cs-allow-user-registration').hide();",
61
								"$('.cs-allow-user-registration').show();".
62
								"if (!$('.cs-allow-user-registration input[value=1]').prop('checked')) { $('.cs-require-registration-confirmation').hide(); }"
63
							]
64
						]
65
					)
66
				],
67
				[
68
					[
69
						h::info('require_registration_confirmation'),
70
						h::radio(
71
							[
72
								'name'     => 'core[require_registration_confirmation]',
73
								'checked'  => $Config->core['require_registration_confirmation'],
74
								'value'    => [0, 1],
75
								'in'       => [$L->off, $L->on],
76
								'onchange' => [
77
									"$('.cs-require-registration-confirmation').hide();",
78
									"$('.cs-require-registration-confirmation').show();"
79
								]
80
							]
81
						)
82
					],
83
					[
84
						'style' => $Config->core['allow_user_registration'] == 0 ? 'display: none;' : '',
85
						'class' => 'cs-allow-user-registration'
86
					]
87
				],
88
				[
89
					static::core_input('registration_confirmation_time', 'number', null, false, 1, false, $L->days),
90
					[
91
						'style' => $Config->core['allow_user_registration'] == 1 && $Config->core['require_registration_confirmation'] == 1 ? '' :
92
							'display: none;',
93
						'class' => 'cs-allow-user-registration cs-require-registration-confirmation'
94
					]
95
				],
96
				[
97
					static::core_input('auto_sign_in_after_registration', 'radio'),
98
					[
99
						'style' => $Config->core['allow_user_registration'] == 1 && $Config->core['require_registration_confirmation'] == 1 ? '' :
100
							'display: none;',
101
						'class' => 'cs-allow-user-registration cs-require-registration-confirmation'
102
					]
103
				],
104
				static::core_textarea('rules', 'SIMPLE_EDITOR')
105
			)
106
		);
107
	}
108
	static function users_groups () {
109
		$a       = Index::instance();
110
		$a->form = false;
111
		$a->content(
112
			h::cs_system_admin_groups_list()
113
		);
114
	}
115
	static function users_mail () {
116
		$Config              = Config::instance();
117
		$Index               = Index::instance();
118
		$L                   = Language::instance();
119
		$Index->apply_button = true;
120
		$Index->content(
121
			static::vertical_table(
122
				[
123
					[
124
						h::info('smtp'),
125
						h::radio(
126
							[
127
								'name'    => 'core[smtp]',
128
								'checked' => $Config->core['smtp'],
129
								'value'   => [0, 1],
130
								'in'      => [$L->off, $L->on],
131
								'OnClick' => ["$('#smtp_form').parent().parent().children().hide();", "$('#smtp_form').parent().parent().children().show();"]
132
							]
133
						)
134
					],
135
					[
136
						[
137
							'',
138
							h::{'table#smtp_form tr'}(
139
								h::td(
140
									static::core_input('smtp_host')
141
								),
142
								h::td(
143
									static::core_input('smtp_port')
144
								),
145
								h::td(
146
									[
147
										h::info('smtp_secure'),
148
										h::radio(
149
											[
150
												'name'    => 'core[smtp_secure]',
151
												'checked' => $Config->core['smtp_secure'],
152
												'value'   => ['', 'ssl', 'tls'],
153
												'in'      => [$L->off, 'SSL', 'TLS']
154
											]
155
										)
156
									]
157
								),
158
								h::td(
159
									[
160
										$L->smtp_auth,
161
										h::radio(
162
											[
163
												'name'    => 'core[smtp_auth]',
164
												'checked' => $Config->core['smtp_auth'],
165
												'value'   => [0, 1],
166
												'in'      => [$L->off, $L->on],
167
												'OnClick' => ["$('#smtp_user, #smtp_password').hide();", "$('#smtp_user, #smtp_password').show();"]
168
											]
169
										)
170
									]
171
								),
172
								[
173
									h::td(
174
										static::core_input('smtp_user')
175
									),
176
									[
177
										'style' => (!$Config->core['smtp_auth'] ? 'display: none;' : '').' padding-left: 20px;',
178
										'id'    => 'smtp_user'
179
									]
180
								],
181
								[
182
									h::td(
183
										static::core_input('smtp_password')
184
									),
185
									[
186
										'style' => !$Config->core['smtp_auth'] ? 'display: none;' : '',
187
										'id'    => 'smtp_password'
188
									]
189
								]
190
							)
191
						],
192
						[
193
							'style' => !$Config->core['smtp'] ? 'display: none; ' : ''
194
						]
195
					],
196
					static::core_input('mail_from'),
197
					static::core_input('mail_from_name'),
198
					static::core_textarea('mail_signature', 'SIMPLE_EDITOR'),
199
					[
200
						'',
201
						h::{'td button[is=cs-button][onclick=cs.test_email_sending()]'}($L->test_email_sending)
202
					]
203
				]
204
			)
205
		);
206
	}
207
	static function users_permissions () {
208
		$a       = Index::instance();
209
		$a->form = false;
210
		$a->content(
211
			h::cs_system_admin_permissions_list()
212
		);
213
	}
214
	static function users_security () {
215
		$Config = Config::instance();
216
		$Index  = Index::instance();
217
		$L      = Language::instance();
218
		/**
219
		 * @var \cs\_SERVER $_SERVER
220
		 */
221
		$Index->apply_button = true;
222
		$Index->content(
223
			static::vertical_table(
224
				[
225
					[
226
						h::info('key_expire'),
227
						h::{'input[is=cs-input-text][type=number]'}(
228
							[
229
								'name'  => 'core[key_expire]',
230
								'value' => $Config->core['key_expire'],
231
								'min'   => 1
232
							]
233
						).
234
						$L->seconds
235
					],
236
					[
237
						h::info('ip_black_list'),
238
						h::{'textarea[is=cs-textarea][autosize]'}(
239
							$Config->core['ip_black_list'],
240
							[
241
								'name' => 'core[ip_black_list]'
242
							]
243
						)
244
					],
245
					[
246
						h::info('ip_admin_list_only'),
247
						h::radio(
248
							[
249
								'name'    => 'core[ip_admin_list_only]',
250
								'checked' => $Config->core['ip_admin_list_only'],
251
								'value'   => [0, 1],
252
								'in'      => [$L->off, $L->on]
253
							]
254
						)
255
					],
256
					[
257
						h::info('ip_admin_list'),
258
						h::{'textarea[is=cs-textarea][autosize]'}(
259
							$Config->core['ip_admin_list'],
260
							[
261
								'name' => 'core[ip_admin_list]'
262
							]
263
						).
264
						h::br().
265
						$L->current_ip.': '.h::b($_SERVER->ip)
266
					]
267
				]
268
			)
269
		);
270
	}
271
	static function users_users () {
272
		$L    = Language::instance();
273
		$Page = Page::instance();
274
		$User = User::instance();
275
		$a    = Index::instance();
276
		$rc   = Route::instance()->route;
277
		if (isset($rc[2], $rc[3])) {
278
			$is_bot = in_array(3, (array)$User->get_groups($rc[3]));
279
			switch ($rc[2]) {
280
				case 'groups':
281
					if ($is_bot || !isset($rc[3]) || $rc[3] == User::ROOT_ID) {
282
						break;
283
					}
284
					$a->cancel_button_back = true;
285
					$Group                 = Group::instance();
286
					$user_groups           = array_reverse($User->get_groups($rc[3]));
287
					$all_groups            = $Group->get_all();
288
					$groups_selected       = h::{'li.cs-block-primary.cs-text.primary'}(
289
						$L->selected_groups
290
					);
291
					$groups_list           = h::{'li.cs-block-primary.cs-text.primary'}(
292
						$L->other_groups
293
					);
294
					if (is_array($user_groups) && !empty($user_groups)) {
295
						foreach ($user_groups as $group) {
296
							$group = $Group->get($group);
297
							$groups_selected .= h::{'li.cs-block-success.cs-text-success'}(
298
								$group['title'],
299
								[
300
									'data-id' => $group['id'],
301
									'tooltip' => $group['description']
302
								]
303
							);
304
						}
305
					}
306
					if (is_array($all_groups) && !empty($all_groups)) {
307
						foreach ($all_groups as $group) {
308
							if ($group['id'] == User::BOT_GROUP_ID || in_array($group['id'], $user_groups)) {
309
								continue;
310
							}
311
							$groups_list .= h::{'li.cs-block-warning.cs-text-warning'}(
312
								$group['title'],
313
								[
314
									'data-id' => $group['id'],
315
									'tooltip' => $group['description']
316
								]
317
							);
318
						}
319
					}
320
					$Page->title(
321
						$L->user_groups($User->username($rc[3]))
0 ignored issues
show
Documentation Bug introduced by
The method user_groups does not exist on object<cs\Language>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
322
					);
323
					$a->content(
324
						h::{'h2.cs-text-center'}(
325
							$L->user_groups(
0 ignored issues
show
Documentation Bug introduced by
The method user_groups does not exist on object<cs\Language>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
326
								$User->username($rc[3])
327
							),
328
							[
329
								'tooltip' => $L->user_groups_info
330
							]
331
						).
332
						h::{'div'}(
333
							h::{'ul#cs-users-groups-list-selected'}($groups_selected).
334
							h::{'ul#cs-users-groups-list'}($groups_list)
335
						).
336
						h::{'input[type=hidden]'}(
337
							[
338
								'name'  => 'user[id]',
339
								'value' => $rc[3]
340
							]
341
						).
342
						h::{'input#cs-user-groups[type=hidden]'}(
343
							[
344
								'name' => 'user[groups]'
345
							]
346
						)
347
					);
348
					break;
349
			}
350
			$a->content(
351
				h::{'input[type=hidden]'}(
352
					[
353
						'name'  => 'mode',
354
						'value' => $rc[2]
355
					]
356
				)
357
			);
358
		} else {
359
			$a->form = false;
360
			$a->content(
361
				h::{'cs-system-admin-users-list'}()
362
			);
363
		}
364
	}
365
}
366