分享访问日志的一部分后端实现
*该功能的日志记录仍未实装
This commit is contained in:
parent
b0e4867b68
commit
8996158fb5
@ -2,6 +2,7 @@
|
||||
|
||||
namespace app\controllers;
|
||||
|
||||
use app\models\DownloadLogs;
|
||||
use app\models\LoginLogs;
|
||||
use app\models\SiteConfig;
|
||||
use app\models\User;
|
||||
@ -34,7 +35,7 @@ class AdminController extends Controller
|
||||
'rules' => [
|
||||
[
|
||||
'allow' => true,
|
||||
'actions' => ['index', 'system', 'user', 'info', 'user-view', 'user-create', 'user-update', 'user-delete', 'user-totpoff', 'user-pwdreset', 'login-log'],
|
||||
'actions' => ['index', 'system', 'user', 'info', 'user-view', 'user-create', 'user-update', 'user-delete', 'user-totpoff', 'user-pwdreset', 'login-log','access-log'],
|
||||
'roles' => ['admin'], // only admin can do these
|
||||
]
|
||||
],
|
||||
@ -53,6 +54,7 @@ class AdminController extends Controller
|
||||
'user-totpoff' => ['POST'],
|
||||
'user-pwdreset' => ['POST'],
|
||||
'login-log' => ['GET'],
|
||||
'access-log' => ['GET'],
|
||||
],
|
||||
],
|
||||
]
|
||||
@ -395,4 +397,16 @@ class AdminController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function actionAccessLog(): string
|
||||
{
|
||||
$downloadLogs = new DownloadLogs();
|
||||
$dataProvider = $downloadLogs->search($this->request->queryParams);
|
||||
return $this->render('access_log', [
|
||||
'searchModel' => $downloadLogs,
|
||||
'dataProvider' => $dataProvider,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace app\models;
|
||||
|
||||
use yii\data\ActiveDataProvider;
|
||||
use yii\db\ActiveQuery;
|
||||
use yii\db\ActiveRecord;
|
||||
|
||||
@ -96,4 +97,42 @@ class DownloadLogs extends ActiveRecord
|
||||
|
||||
$log->save();
|
||||
}
|
||||
|
||||
public function search($params): ActiveDataProvider
|
||||
{
|
||||
$query = DownloadLogs::find();
|
||||
|
||||
// add conditions that should always apply here
|
||||
|
||||
$dataProvider = new ActiveDataProvider([
|
||||
'query' => $query,
|
||||
'sort' => [
|
||||
'defaultOrder' => [
|
||||
'id' => SORT_DESC, // 默认按照 'id' 倒序排序
|
||||
]
|
||||
],
|
||||
]);
|
||||
|
||||
$this->load($params);
|
||||
|
||||
if (!$this->validate()) {
|
||||
// uncomment the following line if you do not want to return any records when validation fails
|
||||
// $query->where('0=1');
|
||||
return $dataProvider;
|
||||
}
|
||||
|
||||
// grid filtering conditions
|
||||
$query->andFilterWhere([
|
||||
'id' => $this->id,
|
||||
'user_id' => $this->user_id,
|
||||
'share_id' => $this->share_id,
|
||||
'access_time' => $this->access_time,
|
||||
]);
|
||||
|
||||
$query->andFilterWhere(['like', 'ip_address', $this->ip_address])
|
||||
->andFilterWhere(['like', 'user_agent', $this->user_agent]);
|
||||
|
||||
|
||||
return $dataProvider;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user