Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wolfcode
EasyAdmin8-Laravel
提交
f45e832d
E
EasyAdmin8-Laravel
项目概览
wolfcode
/
EasyAdmin8-Laravel
6 个月 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
EasyAdmin8-Laravel
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
f45e832d
编写于
8月 07, 2023
作者:
W
wolfcode
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update .
上级
594a1dbc
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
36 addition
and
23 deletion
+36
-23
app/Exceptions/Handler.php
app/Exceptions/Handler.php
+1
-1
app/Http/Controllers/admin/AjaxController.php
app/Http/Controllers/admin/AjaxController.php
+1
-1
app/Http/Middleware/CheckAuth.php
app/Http/Middleware/CheckAuth.php
+15
-1
app/Http/Services/AuthService.php
app/Http/Services/AuthService.php
+19
-20
未找到文件。
app/Exceptions/Handler.php
浏览文件 @
f45e832d
...
...
@@ -45,7 +45,7 @@ class Handler extends ExceptionHandler
//系统默认错误
if
(
config
(
'app.debug'
))
{
return
response
()
->
make
(
$e
->
getMessage
()
);
return
parent
::
render
(
$request
,
$e
);
}
}
}
app/Http/Controllers/admin/AjaxController.php
浏览文件 @
f45e832d
...
...
@@ -22,7 +22,7 @@ class AjaxController extends AdminController
{
$cacheData
=
Cache
::
get
(
'initAdmin_'
.
session
(
'admin.id'
));
if
(
!
empty
(
$cacheData
))
{
return
json
(
$cacheData
);
//
return json($cacheData);
}
$menuService
=
new
MenuService
(
session
(
'admin.id'
));
$data
=
[
...
...
app/Http/Middleware/CheckAuth.php
浏览文件 @
f45e832d
...
...
@@ -4,6 +4,7 @@ namespace App\Http\Middleware;
use
App\Http\Controllers\admin\ErrorPageController
;
use
App\Http\JumpTrait
;
use
App\Http\Services\AuthService
;
use
Closure
;
use
Illuminate\Http\Request
;
use
Symfony\Component\HttpFoundation\Response
;
...
...
@@ -24,8 +25,8 @@ class CheckAuth
$adminConfig
=
config
(
'admin'
);
$parameters
=
request
()
->
route
()
->
parameters
;
$controller
=
$parameters
[
'controller'
]
??
'index'
;
$adminId
=
session
(
'admin.id'
,
0
);
if
(
!
in_array
(
$controller
,
$adminConfig
[
'no_login_controller'
]))
{
$adminId
=
session
(
'admin.id'
);
$expireTime
=
session
(
'admin.expire_time'
);
if
(
empty
(
$adminId
))
{
return
$this
->
responseView
(
'请先登录后台'
,
[],
__url
(
"/login"
));
...
...
@@ -36,6 +37,19 @@ class CheckAuth
return
$this
->
responseView
(
'登录已过期,请重新登录'
,
[],
__url
(
"/login"
));
}
}
// 验证权限
if
(
$adminId
)
{
$authService
=
app
(
AuthService
::
class
,
[
'adminId'
=>
$adminId
]);
$currentNode
=
$authService
->
getCurrentNode
();
if
(
!
in_array
(
$controller
,
$adminConfig
[
'no_auth_controller'
])
&&
!
in_array
(
$controller
,
$adminConfig
[
'no_auth_node'
]))
{
$check
=
$authService
->
checkNode
(
$currentNode
);
if
(
!
$check
)
return
$this
->
error
(
'无权限访问'
);
// 判断是否为演示环境
if
(
env
(
'EASYADMIN.IS_DEMO'
,
false
)
&&
\
request
()
->
method
()
==
'POST'
)
{
return
$this
->
responseView
(
'演示环境下不允许修改'
);
}
}
}
return
$next
(
$request
);
}
}
app/Http/Services/AuthService.php
浏览文件 @
f45e832d
...
...
@@ -3,6 +3,8 @@
namespace
App\Http\Services
;
use
Illuminate\Support\Facades\DB
;
use
Illuminate\Support\Facades\Route
;
use
Illuminate\Support\Str
;
/**
* 权限验证服务
...
...
@@ -86,7 +88,7 @@ class AuthService
if
(
!
isset
(
$this
->
nodeList
[
$node
]))
{
return
false
;
}
$nodeInfo
=
$this
->
nodeList
[
$node
]
;
$nodeInfo
=
get_object_vars
(
$this
->
nodeList
[
$node
])
;
if
(
$nodeInfo
[
'is_auth'
]
==
0
)
{
return
true
;
}
...
...
@@ -95,7 +97,7 @@ class AuthService
return
false
;
}
// 判断该节点是否允许访问
if
(
i
n_array
(
$node
,
$this
->
adminNode
))
{
if
(
i
sset
(
$this
->
adminNode
[
$node
]
))
{
return
true
;
}
return
false
;
...
...
@@ -105,9 +107,10 @@ class AuthService
* 获取当前节点
* @return string
*/
public
function
getCurrentNode
()
public
function
getCurrentNode
()
:
string
{
return
$this
->
parseNodeStr
(
request
()
->
controller
()
.
'/'
.
request
()
->
action
());
$parameters
=
request
()
->
route
()
->
parameters
??
[];
return
(
$parameters
[
'secondary'
]
??
''
)
.
'.'
.
(
$parameters
[
'controller'
]
??
''
)
.
'/'
.
(
$parameters
[
'action'
]
??
''
);
}
/**
...
...
@@ -124,20 +127,16 @@ class AuthService
])
->
first
();
$adminInfo
=
get_object_vars
(
$adminInfo
);
if
(
!
empty
(
$adminInfo
)
&&
!
empty
(
$adminInfo
[
'auth_ids'
]))
{
$buildAuthSql
=
DB
::
table
(
$this
->
config
[
'system_auth'
])
->
distinct
(
true
)
->
whereIn
(
'id'
,
$adminInfo
[
'auth_ids'
])
->
select
(
'id'
)
->
toSql
();
$buildAuthNodeSql
=
DB
::
table
(
$this
->
config
[
'system_auth_node'
])
->
distinct
(
true
)
->
where
(
"auth_id IN
{
$buildAuthSql
}
"
)
->
select
(
'node_id'
)
->
toSql
();
$nodeList
=
DB
::
table
(
$this
->
config
[
'system_node'
])
->
distinct
(
true
)
->
where
(
"id IN
{
$buildAuthNodeSql
}
"
)
->
get
()
->
keyBy
(
'node'
)
->
toArray
();
$nodeIds
=
DB
::
table
(
$this
->
config
[
'system_auth_node'
])
->
whereIn
(
'auth_id'
,
explode
(
','
,
$adminInfo
[
'auth_ids'
]))
->
select
(
'node_id'
)
->
get
()
->
map
(
function
(
$value
)
{
return
(
array
)
$value
;
})
->
toArray
();
$nodeList
=
DB
::
table
(
$this
->
config
[
'system_node'
])
->
whereIn
(
'id'
,
$nodeIds
)
->
get
()
->
keyBy
(
'node'
)
->
map
(
function
(
$value
)
{
return
(
array
)
$value
;
})
->
toArray
();
}
return
$nodeList
;
}
...
...
@@ -160,14 +159,14 @@ class AuthService
* @param string $node
* @return string
*/
public
function
parseNodeStr
(
$node
):
string
public
function
parseNodeStr
(
string
$node
):
string
{
$array
=
explode
(
'/'
,
$node
);
foreach
(
$array
as
$key
=>
$val
)
{
if
(
$key
==
0
)
{
$val
=
explode
(
'.'
,
$val
);
foreach
(
$val
as
&
$vo
)
{
$vo
=
\
think\helper\
Str
::
snake
(
lcfirst
(
$vo
));
$vo
=
Str
::
snake
(
lcfirst
(
$vo
));
}
$val
=
implode
(
'.'
,
$val
);
$array
[
$key
]
=
$val
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录