|
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\api\Controller\admin\users; |
|
11
|
|
|
use |
|
12
|
|
|
cs\Cache, |
|
13
|
|
|
cs\Config, |
|
14
|
|
|
cs\ExitException, |
|
15
|
|
|
cs\Page; |
|
16
|
|
|
trait general { |
|
17
|
|
|
/** |
|
18
|
|
|
* Get general users settings |
|
19
|
|
|
*/ |
|
20
|
|
|
static function admin_users_general_get_settings () { |
|
21
|
|
|
$Config = Config::instance(); |
|
22
|
|
|
Page::instance()->json( |
|
23
|
|
|
[ |
|
24
|
|
|
'session_expire' => $Config->core['session_expire'], |
|
25
|
|
|
'sign_in_attempts_block_count' => $Config->core['sign_in_attempts_block_count'], |
|
26
|
|
|
'sign_in_attempts_block_time' => $Config->core['sign_in_attempts_block_time'], |
|
27
|
|
|
'remember_user_ip' => $Config->core['remember_user_ip'], |
|
28
|
|
|
'password_min_length' => $Config->core['password_min_length'], |
|
29
|
|
|
'password_min_strength' => $Config->core['password_min_strength'], |
|
30
|
|
|
'allow_user_registration' => $Config->core['allow_user_registration'], |
|
31
|
|
|
'require_registration_confirmation' => $Config->core['require_registration_confirmation'], |
|
32
|
|
|
'registration_confirmation_time' => $Config->core['registration_confirmation_time'], |
|
33
|
|
|
'auto_sign_in_after_registration' => $Config->core['auto_sign_in_after_registration'], |
|
34
|
|
|
'rules' => get_core_ml_text('rules'), |
|
35
|
|
|
'simple_admin_mode' => $Config->core['simple_admin_mode'], |
|
36
|
|
|
'applied' => $Config->cancel_available() |
|
37
|
|
|
] |
|
38
|
|
|
); |
|
39
|
|
|
} |
|
40
|
|
|
/** |
|
41
|
|
|
* Apply general users settings |
|
42
|
|
|
* |
|
43
|
|
|
* @throws ExitException |
|
44
|
|
|
*/ |
|
45
|
|
|
static function admin_users_general_apply_settings () { |
|
46
|
|
|
static::admin_users_general_settings_common(); |
|
47
|
|
|
if (!Config::instance()->apply()) { |
|
48
|
|
|
throw new ExitException(500); |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
/** |
|
52
|
|
|
* @throws ExitException |
|
53
|
|
|
*/ |
|
54
|
|
|
protected static function admin_users_general_settings_common () { |
|
55
|
|
|
if (!isset( |
|
56
|
|
|
$_POST['session_expire'], |
|
57
|
|
|
$_POST['sign_in_attempts_block_count'], |
|
58
|
|
|
$_POST['sign_in_attempts_block_time'], |
|
59
|
|
|
$_POST['remember_user_ip'], |
|
60
|
|
|
$_POST['password_min_length'], |
|
61
|
|
|
$_POST['password_min_strength'], |
|
62
|
|
|
$_POST['allow_user_registration'], |
|
63
|
|
|
$_POST['require_registration_confirmation'], |
|
64
|
|
|
$_POST['registration_confirmation_time'], |
|
65
|
|
|
$_POST['auto_sign_in_after_registration'], |
|
66
|
|
|
$_POST['rules'] |
|
67
|
|
|
) |
|
68
|
|
|
) { |
|
69
|
|
|
throw new ExitException(400); |
|
70
|
|
|
} |
|
71
|
|
|
$Config = Config::instance(); |
|
72
|
|
|
$Config->core['session_expire'] = (int)$_POST['session_expire']; |
|
73
|
|
|
$Config->core['sign_in_attempts_block_count'] = (int)$_POST['sign_in_attempts_block_count']; |
|
74
|
|
|
$Config->core['sign_in_attempts_block_time'] = (int)$_POST['sign_in_attempts_block_time']; |
|
75
|
|
|
$Config->core['remember_user_ip'] = (int)(bool)$_POST['remember_user_ip']; |
|
76
|
|
|
$Config->core['password_min_length'] = (int)$_POST['password_min_length']; |
|
77
|
|
|
$Config->core['password_min_strength'] = (int)$_POST['password_min_strength']; |
|
78
|
|
|
$Config->core['allow_user_registration'] = (int)(bool)$_POST['allow_user_registration']; |
|
79
|
|
|
$Config->core['require_registration_confirmation'] = (int)(bool)$_POST['require_registration_confirmation']; |
|
80
|
|
|
$Config->core['registration_confirmation_time'] = (int)$_POST['registration_confirmation_time']; |
|
81
|
|
|
$Config->core['auto_sign_in_after_registration'] = (int)(bool)$_POST['auto_sign_in_after_registration']; |
|
82
|
|
|
$Config->core['rules'] = set_core_ml_text('rules', xap($_POST['rules'], true)); |
|
83
|
|
|
} |
|
84
|
|
|
/** |
|
85
|
|
|
* Save general users settings |
|
86
|
|
|
* |
|
87
|
|
|
* @throws ExitException |
|
88
|
|
|
*/ |
|
89
|
|
|
static function admin_users_general_save_settings () { |
|
90
|
|
|
static::admin_users_general_settings_common(); |
|
91
|
|
|
if (!Config::instance()->save()) { |
|
92
|
|
|
throw new ExitException(500); |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
/** |
|
96
|
|
|
* Cancel general users settings |
|
97
|
|
|
* |
|
98
|
|
|
* @throws ExitException |
|
99
|
|
|
*/ |
|
100
|
|
|
static function admin_users_general_cancel_settings () { |
|
101
|
|
|
if (!Config::instance()->cancel()) { |
|
102
|
|
|
throw new ExitException(500); |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
|