fix: 修复redis密码 优化权限

This commit is contained in:
Ying
2023-08-04 11:13:14 +08:00
parent 87c4137912
commit 732a385498
14 changed files with 110 additions and 46 deletions

View File

@@ -419,6 +419,7 @@ class AdminController extends BaseController
case 'year':
$value = str_replace(',', '-', $value);
if (strpos($value, '-')) {
$arr = explode(' - ', $value);
if (empty($arr)) {
continue 2;
@@ -454,27 +455,23 @@ class AdminController extends BaseController
case 'time';
case 'datetime';
$value = str_replace(',', '-', $value);
if (strpos($value, '-')) {
$arr = explode(' - ', $value);
if (!array_filter($arr)) {
continue 2;
}
$exp = '=';
$exp = 'between';
if ($arr[0] === '') {
$exp = '<= TIME';
$exp = '<=';
$arr = $arr[1];
} elseif ($arr[1] === '') {
$exp = '>= TIME';
$exp = '>=';
$arr = $arr[0];
}
$where[] = [$field, $exp, $arr];
} else {
$where[] = [$field, '=', $value];
}
break;
case 'blob';
break;

View File

@@ -158,7 +158,7 @@ class BaseController
* @param string $app
* @return Response
*/
protected function retResponseError(string $msg = '404 not found', int $code = 404, string $app = 'index'): Response
protected function responseError(string $msg = '404 not found', int $code = 404, string $app = 'index'): Response
{
if (\request()->expectsJson()) {
return json(['code' => 404, 'msg' => $msg]);

View File

@@ -12,6 +12,7 @@ declare(strict_types=1);
// +----------------------------------------------------------------------
namespace app\admin\controller;
use app\admin\enums\AdminNoticeEnum;
use app\common\service\notice\EmailService;
use app\common\service\utils\FtpService;
use Psr\SimpleCache\InvalidArgumentException;
@@ -185,9 +186,25 @@ class Index extends AdminController
UserThird::count('id'),
];
$workplace = [];
foreach (AdminNoticeEnum::COLLECTION as $item) {
$workplace[$item] = AdminNotice::where([
'admin_id' => get_admin_id(),
'type' => $item
])->count('id');
}
$todoList = AdminNotice::where([
'admin_id' => get_admin_id(),
'type' => AdminNoticeEnum::TODO,
'status' => 0
])->count('id');
return view('/index/console', [
'assetsInfo' => $assetsInfo,
'workplace' => [],
'workplace' => $workplace,
'todoList' => $todoList,
'devOpsData' => json_encode($devOpsData, JSON_UNESCAPED_UNICODE),
'searchWords' => json_encode($searchWords, JSON_UNESCAPED_UNICODE),
'userGroupData' => json_encode($userGroupData, JSON_UNESCAPED_UNICODE),

View File

@@ -15,7 +15,9 @@ use app\admin\service\AdminRuleService;
use app\AdminController;
use app\common\model\system\AdminRules as AdminRuleModel;
use support\Response;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use Webman\Http\Request;
/**
@@ -60,15 +62,29 @@ class AdminRules extends AdminController
return $this->success('添加菜单成功!');
}
}
return $this->error('添加菜单失败!');
$data = $this->getTableFields();
$data['pid'] = input('pid', 0);
$data['auth'] = 1;
$data['type'] = 1;
list($count, $list) = AdminRuleService::dataList(request()->all());
return view('/system/admin/rules_edit', [
'data' => $data,
'rules' => json_encode( list_to_tree($list), JSON_UNESCAPED_UNICODE),
]);
}
/**
* 编辑节点数据
/**
* 编辑节点数据
* @return Response
*/
* @throws DbException
* @throws DataNotFoundException
* @throws ModelNotFoundException
*/
public function edit(): Response
{
$id = input('id', 0);
$data = $this->model->find($id);
if (request()->isPost()) {
$post = \request()->post();
validate(\app\common\validate\system\AdminRules::class . '.edit')->check($post);
@@ -76,7 +92,12 @@ class AdminRules extends AdminController
return $this->success('更新菜单成功!');
}
}
return $this->error('更新菜单失败');
list($count, $list) = AdminRuleService::dataList(request()->all());
return view('/system/admin/rules_edit', [
'data' => $data,
'rules' => json_encode( list_to_tree($list), JSON_UNESCAPED_UNICODE),
]);
}
/**

View File

@@ -53,7 +53,7 @@ class AdminGroupService
// 查询数据
$count = $model->where($where)->count();
$page = ($count <= $limit) ? 1 : $page;
$list = $model->where($where)->order("id asc")->limit($limit)->page($page)->select()->toArray();
$list = $model->where($where)->order("id asc")->limit((int)$limit)->page((int)$page)->select()->toArray();
return [$count, $list];
}

View File

@@ -62,7 +62,7 @@ class ApiPermissions implements MiddlewareInterface
// 是否验证登录器
$userInfo = UserTokenService::isLogin();
if (!empty($userInfo)) {
if (!empty($userInfo) && isset($userInfo['id'])) {
$request->userId = $userInfo['id'];
$request->userInfo = $userInfo;
// 是否验证API权限

View File

@@ -57,6 +57,11 @@ class ExceptionHandle extends ExceptionHandler
{
switch (true) {
case $exception instanceof OperateException:
return json([
'code' => $exception->getCode() ?? 101,
'msg' => $exception->getMessage(),
'data' => $exception->getData()
]);
case $exception instanceof ValidateException:
return json(['code' => $exception->getCode() ?? 101, 'msg' => $exception->getMessage()]);
case $exception instanceof DumpException:

View File

@@ -24,4 +24,13 @@ class OperateException extends \Exception
$this->message = $message ?: ResultCode::UNKNOWN['msg'];
parent::__construct($this->message, $this->code, $previous);
}
/**
* 获取附加数据
* @return array
*/
public function getData(): array
{
return $this->data;
}
}

View File

@@ -405,9 +405,22 @@ class Upload
*/
public function fileFilter($file): bool
{
$this->fileClass = null;
$mineType = $file->getUploadMineType();
if (in_array($mineType, ['text/x-php', 'text/html'])) {
$this->_error = '禁止上传的文件类型';
return false;
}
$validate = new UploadFile();
$rules = get_object_vars($validate)['rule'];
$fileExt = $this->getFileExt($file);
$fileExt = $file->getUploadExtension() ?: input('fileExt');
if (empty($fileExt)) {
$this->fileClass = 'file';
return true;
}
foreach ($rules as $key => $value) {
$fileExtArr = explode(',', $value['fileExt']);
if (in_array(strtolower($fileExt), $fileExtArr)) {
@@ -419,15 +432,13 @@ class Upload
break;
}
}
if (in_array($file->getUploadMineType(), ['text/x-php', 'text/html'])) {
$this->fileClass = null;
}
if (is_empty($this->fileClass)) {
$this->_error = '禁止上传的文件类型';
return false;
}
// 未找到类型或验证文件失败
return !empty($this->fileClass);
return true;
}
/**
@@ -447,7 +458,10 @@ class Upload
* @param string $filePath
* @param array $extend
* @return array
* @throws DataNotFoundException
* @throws DbException
* @throws InvalidArgumentException
* @throws ModelNotFoundException
*/
public function success(string $msg, string $filePath, array $extend = []): array
{

View File

@@ -9,30 +9,30 @@ class UploadFile extends Validate
{
/**
* 定义验证规则
* 格式:'字段名' => ['规则1','规则2'...]
* 格式:'字段名' => ['规则1','规则2'...]
*
* @var array
*/
public $rule = [
'images'=>[
'fileSize' => 419430400,
'fileExt' => 'jpg,jpeg,png,bmp,gif,svg,webp',
'fileMime' => 'image/jpeg,image/png,image/gif,image/svg+xml'],
'video'=>[
'fileSize' => 419430400,
'fileExt' => 'flv,swf,mkv,avi,rm,rmvb,mpeg,mpg,ogg,ogv,mov,wmv,mp4,webm,mp3,wav,mid'],
'document'=>[
'fileSize' => 419430400,
'fileExt' => 'txt,doc,xls,ppt,docx,xlsx,pptx'],
'files'=>[
'fileSize' => 419430400,
'fileExt' => 'exe,dll,sys,so,dmg,iso,zip,rar,7z,sql,pem,pdf,psd']
];
*/
public $rule = [
'images' => [
'fileSize' => 419430400,
'fileExt' => 'jpg,jpeg,png,bmp,gif,svg,webp',
'fileMime' => 'image/jpeg,image/png,image/gif,image/svg+xml'],
'video' => [
'fileSize' => 419430400,
'fileExt' => 'flv,swf,mkv,avi,rm,rmvb,mpeg,mpg,ogg,ogv,mov,wmv,mp4,webm,mp3,wav,mid'],
'document' => [
'fileSize' => 419430400,
'fileExt' => 'txt,doc,xls,ppt,docx,xlsx,pptx'],
'files' => [
'fileSize' => 419430400,
'fileExt' => 'exe,dll,sys,so,dmg,iso,zip,rar,7z,sql,pem,pdf,psd']
];
/**
* 定义错误信息
* 格式:'字段名.规则名' => '错误信息'
* 格式:'字段名.规则名' => '错误信息'
*
* @var array
*/
*/
protected $message = [];
}

View File

@@ -1109,14 +1109,16 @@ if (!function_exists('check_user_third')) {
}
}
if (!function_exists('check_admin_auth')) {
if (!function_exists('has_admin_auth')) {
/**
* 检查admin权限
* @param $method
* @return bool
*/
function check_admin_auth($method): bool
function has_admin_auth($method): bool
{
if (\app\admin\service\AuthService::instance()->SuperAdmin()) {
return true;
}

View File

@@ -38,7 +38,7 @@ return [
'dispatch_success' => app_path() . '/admin/view/public/jumptpl.html',
'exception_tpl' => app_path() . '/admin/view/error/500.html',
'error_message' => '页面错误!请稍后再试~',
'version' => 'v1.1.8',
'version' => 'v1.1.9',
'cors_domain' => ['*', '127.0.0.1'],
'api_url' => 'https://api.swiftadmin.net/',
'show_error_msg' => false,

View File

@@ -15,7 +15,7 @@
return [
'default' => [
'host' => get_env('CACHE_HOSTNAME', '127.0.0.1'),
'password' => get_env('REDIS_PASSWORD', null),
'password' => get_env('CACHE_PASSWORD', null),
'port' => (int)get_env('CACHE_HOSTPORT',6379),
'database' => get_env('CACHE_SELECT', 0),
'prefix' => 'redis_',

View File

@@ -111,7 +111,6 @@ class ZipArchives
}
} catch (\Throwable $th) {
var_dump($th->getMessage());
throw new \Exception("压缩 " . $fileName . " 包失败", -115);
} finally {
$zip->close();