mirror of
https://gitee.com/apiadmin/ApiAdmin.git
synced 2025-04-06 03:58:00 +08:00
added 操作日志的记录
This commit is contained in:
parent
b0fc40155c
commit
ec990e967c
52
application/admin/behavior/AdminLog.php
Normal file
52
application/admin/behavior/AdminLog.php
Normal file
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
/**
|
||||
* 后台操作日志记录
|
||||
* @since 2018-02-28
|
||||
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
||||
*/
|
||||
|
||||
namespace app\admin\behavior;
|
||||
|
||||
|
||||
use app\model\ApiMenu;
|
||||
use app\model\ApiUserAction;
|
||||
use app\util\ReturnCode;
|
||||
use think\Request;
|
||||
|
||||
class AdminLog {
|
||||
|
||||
/**
|
||||
* 后台操作日志记录
|
||||
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
||||
* @return \think\response\Json
|
||||
* @throws \think\Exception
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function run() {
|
||||
$header = config('apiAdmin.CROSS_DOMAIN');
|
||||
$request = Request::instance();
|
||||
$route = $request->routeInfo();
|
||||
$userToken = $request->header('ApiAuth', '');
|
||||
$userInfo = cache($userToken);
|
||||
$userInfo = json_decode($userInfo, true);
|
||||
$menuInfo = ApiMenu::get(['url' => $route['route']]);
|
||||
|
||||
if ($menuInfo) {
|
||||
$menuInfo = $menuInfo->toArray();
|
||||
} else {
|
||||
$data = ['code' => ReturnCode::INVALID, 'msg' => '当前路由非法:'. $route['route'], 'data' => []];
|
||||
|
||||
return json($data, 200, $header);
|
||||
}
|
||||
|
||||
ApiUserAction::create([
|
||||
'actionName' => $menuInfo['name'],
|
||||
'uid' => $userInfo['id'],
|
||||
'nickname' => $userInfo['nickname'],
|
||||
'addTime' => time(),
|
||||
'url' => $route['route'],
|
||||
'data' => json_encode($request->param())
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
@ -13,8 +13,6 @@ use think\Request;
|
||||
|
||||
class ApiAuth {
|
||||
|
||||
private $exclude = [];
|
||||
|
||||
/**
|
||||
* 默认行为函数
|
||||
* @return \think\response\Json
|
||||
@ -23,9 +21,9 @@ class ApiAuth {
|
||||
public function run() {
|
||||
$request = Request::instance();
|
||||
$header = config('apiAdmin.CROSS_DOMAIN');
|
||||
$userToken = $request->header('ApiAuth', '');
|
||||
if ($userToken) {
|
||||
$userInfo = cache($userToken);
|
||||
$ApiAuth = $request->header('ApiAuth', '');
|
||||
if ($ApiAuth) {
|
||||
$userInfo = cache($ApiAuth);
|
||||
$userInfo = json_decode($userInfo, true);
|
||||
if (!$userInfo || !isset($userInfo['id'])) {
|
||||
$data = ['code' => ReturnCode::AUTH_ERROR, 'msg' => 'ApiAuth不匹配', 'data' => []];
|
||||
|
@ -29,8 +29,8 @@ class ApiPermission {
|
||||
$request = Request::instance();
|
||||
$route = $request->routeInfo();
|
||||
$header = config('apiAdmin.CROSS_DOMAIN');
|
||||
$userToken = $request->header('ApiAuth', '');
|
||||
$userInfo = cache($userToken);
|
||||
$ApiAuth = $request->header('ApiAuth', '');
|
||||
$userInfo = cache($ApiAuth);
|
||||
$userInfo = json_decode($userInfo, true);
|
||||
if (!$this->checkAuth($userInfo['id'], $route['route'])) {
|
||||
$data = ['code' => ReturnCode::INVALID, 'msg' => '非常抱歉,您没有权限怎么做!', 'data' => []];
|
||||
|
@ -1,11 +1,15 @@
|
||||
<?php
|
||||
$afterBehavior = ['\app\admin\behavior\ApiAuth', '\app\admin\behavior\ApiPermission'];
|
||||
$afterBehavior = [
|
||||
'\app\admin\behavior\ApiAuth',
|
||||
'\app\admin\behavior\ApiPermission',
|
||||
'\app\admin\behavior\AdminLog'
|
||||
];
|
||||
|
||||
return [
|
||||
'[admin]' => [
|
||||
'Login/index' => [
|
||||
'admin/Login/index',
|
||||
['method' => 'post']
|
||||
['method' => 'post', 'after_behavior' => '\app\admin\behavior\AdminLog']
|
||||
],
|
||||
'Login/logout' => [
|
||||
'admin/Login/logout',
|
||||
|
Loading…
x
Reference in New Issue
Block a user