Skip to content

Commit

Permalink
no message
Browse files Browse the repository at this point in the history
  • Loading branch information
kuaifan committed Apr 6, 2022
1 parent 8237cd2 commit 9bc56f5
Show file tree
Hide file tree
Showing 5 changed files with 415 additions and 23 deletions.
42 changes: 27 additions & 15 deletions app/Http/Controllers/Api/SystemController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class SystemController extends AbstractController
* @apiParam {String} type
* - get: 获取(默认)
* - all: 获取所有(需要管理员权限)
* - save: 保存设置(参数:regreg_invitelogin_codepassword_policyproject_invitechat_nicknameauto_archivedarchived_daystart_homehome_footer)
* - save: 保存设置(参数:['reg', 'reg_invite', 'login_code', 'password_policy', 'project_invite', 'chat_nickname', 'auto_archived', 'archived_day', 'start_home', 'home_footer']
* @apiSuccess {Number} ret 返回状态码(1正确、0错误)
* @apiSuccess {String} msg 返回信息(错误描述)
Expand All @@ -41,7 +41,18 @@ public function setting()
User::auth('admin');
$all = Request::input();
foreach ($all AS $key => $value) {
if (!in_array($key, ['reg', 'reg_invite', 'login_code', 'password_policy', 'project_invite', 'chat_nickname', 'auto_archived', 'archived_day', 'start_home', 'home_footer'])) {
if (!in_array($key, [
'reg',
'reg_invite',
'login_code',
'password_policy',
'project_invite',
'chat_nickname',
'auto_archived',
'archived_day',
'start_home',
'home_footer'
])) {
unset($all[$key]);
}
}
Expand Down Expand Up @@ -78,31 +89,40 @@ public function setting()
}

/**
* @api {get} api/system/setting/email 02. 获取邮箱设置、保存邮箱设置
* @api {get} api/system/setting/email 02. 获取邮箱设置、保存邮箱设置(限管理员)
*
* @apiVersion 1.0.0
* @apiGroup system
* @apiName setting__email
*
* @apiParam {String} type
* - get: 获取(默认)
* - all: 获取所有(需要管理员权限)
* - save: 保存设置(参数:smtp_server port account password reg_verify notice task_remind_hours task_remind_hours2)
* - save: 保存设置(参数:['smtp_server', 'port', 'account', 'password', 'reg_verify', 'notice', 'task_remind_hours', 'task_remind_hours2'])
* @apiSuccess {Number} ret 返回状态码(1正确、0错误)
* @apiSuccess {String} msg 返回信息(错误描述)
* @apiSuccess {Object} data 返回数据
*/
public function setting__email()
{
User::auth('admin');
//
$type = trim(Request::input('type'));
if ($type == 'save') {
if (env("SYSTEM_SETTING") == 'disabled') {
return Base::retError('当前环境禁止修改');
}
User::auth('admin');
$all = Request::input();
foreach ($all as $key => $value) {
if (!in_array($key, ['smtp_server', 'port', 'account', 'password', 'reg_verify', 'notice', 'task_remind_hours', 'task_remind_hours2'])) {
if (!in_array($key, [
'smtp_server',
'port',
'account',
'password',
'reg_verify',
'notice',
'task_remind_hours',
'task_remind_hours2'
])) {
unset($all[$key]);
}
}
Expand All @@ -111,13 +131,6 @@ public function setting__email()
$setting = Base::setting('emailSetting');
}
//
if ($type == 'all' || $type == 'save') {
User::auth('admin');
$setting['reg_invite'] = $setting['reg_invite'] ?: Base::generatePassword(8);
} else {
if (isset($setting['reg_invite'])) unset($setting['reg_invite']);
}
//
$setting['smtp_server'] = $setting['smtp_server'] ?: '';
$setting['port'] = $setting['port'] ?: '';
$setting['account'] = $setting['account'] ?: '';
Expand Down Expand Up @@ -533,7 +546,6 @@ public function fileupload()
return $data;
}


/**
* @api {get} api/system/get/starthome 14. 启动首页设置信息
*
Expand Down
17 changes: 11 additions & 6 deletions app/Module/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -1218,11 +1218,12 @@ public static function strReplaceLimit($search, $replace, $subject, $limit = -1)

/**
* 获取或设置
* @param $setname //配置名称
* @param bool $array //保存内容
* @param $setname // 配置名称
* @param bool $array // 保存内容
* @param false $isUpdate // 保存内容为更新模式,默认否
* @return array
*/
public static function setting($setname, $array = false)
public static function setting($setname, $array = false, $isUpdate = false)
{
global $_A;
if (empty($setname)) {
Expand All @@ -1233,15 +1234,19 @@ public static function setting($setname, $array = false)
}
$setting = [];
$row = Setting::whereName($setname)->first();
if (!empty($row)) {
if ($row) {
$setting = Base::string2array($row->setting);
} else {
$row = Setting::createInstance(['name' => $setname]);
$row->save();
}
if ($array !== false) {
$setting = $array;
$row->updateInstance(['setting' => $array]);
if ($isUpdate && is_array($array)) {
$setting = array_merge($setting, $array);
} else {
$setting = $array;
}
$row->updateInstance(['setting' => $setting]);
$row->save();
}
$_A["__static_setting_" . $setname] = $setting;
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"ext-simplexml": "*",
"fideloper/proxy": "^4.4.1",
"fruitcake/laravel-cors": "^2.0.4",
"guanguans/notify": "^1.20",
"guzzlehttp/guzzle": "^7.3.0",
"laravel/framework": "^v8.48.1",
"laravel/tinker": "^v2.6.1",
Expand Down
Loading

0 comments on commit 9bc56f5

Please sign in to comment.