forked from kuafuRace/phprap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSettingController.php
More file actions
executable file
·129 lines (81 loc) · 3.35 KB
/
SettingController.php
File metadata and controls
executable file
·129 lines (81 loc) · 3.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?php
namespace app\controllers\admin;
use app\models\Config;
use Yii;
use yii\web\Response;
class SettingController extends PublicController
{
/**
* 基础设置
*
* @return string
*/
public function actionApp()
{
$request = Yii::$app->request;
$response = Yii::$app->response;
$config = Config::findOne(['type' => 'app']);
if($request->isPost){
$response->format = Response::FORMAT_JSON;
$config->content = json_encode($request->post('Config'), JSON_UNESCAPED_UNICODE);
if ($config->save()) {
return ['status' => 'success', 'message' => '保存成功'];
}
return ['status' => 'error', 'message' => $config->getErrorMessage(), 'label' => $config->getErrorLabel()];
}
return $this->display('app', ['config' => $config]);
}
/**
* 邮箱设置
* @return array|string
*/
public function actionEmail()
{
$request = Yii::$app->request;
$response = Yii::$app->response;
$config = Config::findOne(['type' => 'email']);
if($request->isPost){
$response->format = Response::FORMAT_JSON;
$config->content = json_encode($request->post('Config'), JSON_UNESCAPED_UNICODE);
if ($config->save()) {
return ['status' => 'success', 'message' => '保存成功'];
}
return ['status' => 'error', 'message' => $config->getErrorMessage(), 'label' => $config->getErrorLabel()];
}
return $this->display('email', ['config' => $config]);
}
/**
* 安全设置
* @return array|string
*/
public function actionSafe()
{
$request = Yii::$app->request;
$response = Yii::$app->response;
$config = Config::findOne(['type' => 'safe']);
if($request->isPost){
$response->format = Response::FORMAT_JSON;
$data = $request->post('Config');
// 判断输入IP是否同时存在于白名单和黑名单
$ip_white_list = explode("\r\n", trim($data['ip_white_list']));
$ip_black_list = explode("\r\n", trim($data['ip_black_list']));
$conflict_list = array_intersect($ip_white_list, $ip_black_list);
if(array_filter($conflict_list)){
return ['status' => 'error', 'message' => '黑名单和白名单里不能出现相同的IP'];
}
// 判断邮箱后缀是否同时存在于白名单和黑名单
$email_white_list = explode('\r\n', trim($data['email_white_list']));
$email_black_list = explode('\r\n', trim($data['email_black_list']));
$conflict_list = array_intersect($email_white_list, $email_black_list);
if(array_filter($conflict_list)){
return ['status' => 'error', 'message' => '黑名单和白名单里不能出现相同的邮箱后缀'];
}
$config->content = json_encode($data, JSON_UNESCAPED_UNICODE);
if ($config->save()) {
return ['status' => 'success', 'message' => '保存成功'];
}
return ['status' => 'error', 'message' => $config->getErrorMessage(), 'label' => $config->getErrorLabel()];
}
return $this->display('safe', ['config' => $config]);
}
}