mirror of
https://gitee.com/apiadmin/ApiAdmin.git
synced 2025-04-06 03:58:00 +08:00
modified 完成全部后端的中间件
This commit is contained in:
parent
8c0cebc37c
commit
cad2716183
@ -2,9 +2,45 @@
|
||||
|
||||
namespace app\http\middleware;
|
||||
|
||||
class AdminLog
|
||||
{
|
||||
public function handle($request, \Closure $next)
|
||||
{
|
||||
use app\model\AdminMenu;
|
||||
use app\model\AdminUserAction;
|
||||
use app\util\ReturnCode;
|
||||
|
||||
class AdminLog {
|
||||
|
||||
/**
|
||||
* @param \think\facade\Request $request
|
||||
* @param \Closure $next
|
||||
* @return \think\response\Json
|
||||
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
||||
*/
|
||||
public function handle($request, \Closure $next) {
|
||||
$ApiAuth = $request->header('ApiAuth');
|
||||
$userInfo = cache('Login:' . $ApiAuth);
|
||||
$userInfo = json_decode($userInfo, true);
|
||||
$menuInfo = AdminMenu::get(['url' => $request->path()]);
|
||||
|
||||
if ($menuInfo) {
|
||||
$menuInfo = $menuInfo->toArray();
|
||||
} else {
|
||||
|
||||
return json([
|
||||
'code' => ReturnCode::INVALID,
|
||||
'msg' => '当前路由非法:' . $request->path(),
|
||||
'data' => []
|
||||
])->header(config('apiadmin.CROSS_DOMAIN'));
|
||||
}
|
||||
|
||||
AdminUserAction::create([
|
||||
'action_name' => $menuInfo['name'],
|
||||
'uid' => $userInfo['id'],
|
||||
'nickname' => $userInfo['nickname'],
|
||||
'add_time' => time(),
|
||||
'url' => $request->path(),
|
||||
'data' => json_encode($request->param())
|
||||
]);
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -23,16 +23,8 @@ class AdminPermission {
|
||||
public function handle($request, \Closure $next) {
|
||||
$ApiAuth = $request->header('ApiAuth');
|
||||
$userInfo = cache('Login:' . $ApiAuth);
|
||||
|
||||
if (!$userInfo) {
|
||||
return json([
|
||||
'code' => ReturnCode::INVALID,
|
||||
'msg' => '非常抱歉,您的登录状态已丢失或已过期!',
|
||||
'data' => []
|
||||
])->header(config('apiadmin.CROSS_DOMAIN'));
|
||||
}
|
||||
|
||||
$userInfo = json_decode($userInfo, true);
|
||||
|
||||
if (!$this->checkAuth($userInfo['id'], $request->path())) {
|
||||
return json([
|
||||
'code' => ReturnCode::INVALID,
|
||||
|
@ -39,7 +39,7 @@ Route::group('admin', function () {
|
||||
'admin/Menu/del',
|
||||
['method' => 'get']
|
||||
]
|
||||
])->middleware('AdminPermission');;
|
||||
])->middleware(['AdminAuth', 'AdminPermission', 'AdminLog']);
|
||||
Route::group('User', [
|
||||
'index' => [
|
||||
'admin/User/index',
|
||||
|
Loading…
x
Reference in New Issue
Block a user