Skip to content

Commit

Permalink
tiaozheng
Browse files Browse the repository at this point in the history
  • Loading branch information
yidashi committed Oct 21, 2016
1 parent bda05bd commit b51dafa
Show file tree
Hide file tree
Showing 14 changed files with 119 additions and 196 deletions.
48 changes: 31 additions & 17 deletions backend/behaviors/AdminLogBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,33 +28,47 @@ public function events()
public function handle()
{
Event::on(ActiveRecord::className(), ActiveRecord::EVENT_AFTER_UPDATE, [$this, 'log']);
Event::on(ActiveRecord::className(), ActiveRecord::EVENT_AFTER_INSERT, [$this, 'log']);
Event::on(ActiveRecord::className(), ActiveRecord::EVENT_AFTER_DELETE, [$this, 'log']);
}

public function log($event)
{
// 显示详情有待优化,不过基本功能完整齐全
if(!empty($event->changedAttributes)) {
if($event->sender instanceof AdminLog) {
return;
}
if ($event->name == ActiveRecord::EVENT_AFTER_INSERT) {
$description = "%s新增了表%s %s:%s的%s";
} elseif($event->name == ActiveRecord::EVENT_AFTER_UPDATE) {
$description = "%s修改了表%s %s:%s的%s";
} else {
$description = "%s删除了表%s %s:%s%s";
}
if (!empty($event->changedAttributes)) {
$desc = '';
foreach($event->changedAttributes as $name => $value) {
$desc .= $name . ' : ' . $value . '=>' . $event->sender->getAttribute($name) . ',';
}
$desc = substr($desc, 0, -1);
$userName = Yii::$app->user->identity->username;
$tableName = $event->sender->tableSchema->name;
$description = "%s修改了表%s %s:%s的%s";
$description = sprintf($description, $userName, $tableName, $event->sender->primaryKey()[0], $event->sender->getPrimaryKey(), $desc);
$route = Url::to();
$userId = Yii::$app->user->id;
$ip = ip2long(Yii::$app->request->userIP);
$data = [
'route' => $route,
'description' => $description,
'user_id' => $userId,
'ip' => $ip
];
$model = new AdminLog();
$model->setAttributes($data);
$model->save();
} else {
$desc = '';
}
$userName = Yii::$app->user->identity->username;
$tableName = $event->sender->tableSchema->name;
$description = sprintf($description, $userName, $tableName, $event->sender->primaryKey()[0], $event->sender->getPrimaryKey(), $desc);

$route = Url::to();
$userId = Yii::$app->user->id;
$ip = ip2long(Yii::$app->request->userIP);
$data = [
'route' => $route,
'description' => $description,
'user_id' => $userId,
'ip' => $ip
];
$model = new AdminLog();
$model->setAttributes($data);
$model->save();
}
}
3 changes: 2 additions & 1 deletion backend/static/js/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
* Created by yidashi on 16/7/28.
*/
$(document).ajaxError(function(event,xhr,options,exc){
$.modal.error('操作失败');
var message = xhr.responseJSON.message || '操作失败';
$.modal.error(message);
});
$.extend(yii, {
confirm: function (message, ok, cancel) {
Expand Down
9 changes: 7 additions & 2 deletions backend/views/comment/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,13 @@
'buttons' => [
'ban' => function($url, $model, $key) {
return Html::a(Html::icon('ban'),
['/user/ban'],
['title' => '封禁用户', 'data-method' => 'post', 'data-params' => ['id' => $model->user_id]]
['/user/admin/block', 'id' => $model->user_id],
[
'title' => '封禁用户',
'data-confirm' => '确定要封禁用户吗?',
'data-ajax' => '1',
'data-method' => 'post'
]
);
}
]
Expand Down
2 changes: 1 addition & 1 deletion backend/views/layouts/content.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
</section>

<section class="content">
<?= \common\widgets\AlertPlus::widget()?>
<?= \common\widgets\Alert::widget()?>
<?= $content ?>
</section>
</div>
Expand Down
1 change: 0 additions & 1 deletion backend/views/layouts/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
/* @var $content string */

backend\assets\AppAsset::register($this);
\common\assets\PaceAsset::register($this);

?>
<?php $this->beginPage() ?>
Expand Down
25 changes: 0 additions & 25 deletions common/assets/PaceAsset.php

This file was deleted.

17 changes: 13 additions & 4 deletions common/modules/user/controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@
namespace common\modules\user\controllers;


use common\models\Album;
use common\modules\user\models\LoginForm;
use common\modules\user\models\Profile;
use common\modules\user\traits\AjaxValidationTrait;
use Yii;
use common\modules\user\models\User;
use yii\base\UserException;
use yii\data\ActiveDataProvider;
use yii\filters\AccessControl;
use yii\filters\VerbFilter;
use yii\helpers\Url;
use yii\web\Controller;
Expand Down Expand Up @@ -188,6 +186,10 @@ public function actionUpdateProfile($id)
public function actionBlock($id)
{
if ($id == \Yii::$app->user->getId()) {
if (Yii::$app->request->isAjax) {
Yii::$app->response->format = 'json';
return ['status' => 0, 'message' => \Yii::t('user', 'You can not block your own account')];
}
\Yii::$app->getSession()->setFlash('danger', \Yii::t('user', 'You can not block your own account'));
} else {
$user = $this->findModel($id);
Expand All @@ -196,13 +198,20 @@ public function actionBlock($id)
}
if ($user->getIsBlocked()) {
$user->unblock();
if (Yii::$app->request->isAjax) {
Yii::$app->response->format = 'json';
return ['message' => \Yii::t('user', 'User has been unblocked')];
}
\Yii::$app->getSession()->setFlash('success', \Yii::t('user', 'User has been unblocked'));
} else {
$user->block();
if (Yii::$app->request->isAjax) {
Yii::$app->response->format = 'json';
return ['message' => \Yii::t('user', 'User has been blocked')];
}
\Yii::$app->getSession()->setFlash('success', \Yii::t('user', 'User has been blocked'));
}
}

return $this->redirect(Url::previous('actions-redirect'));
}

Expand Down
2 changes: 1 addition & 1 deletion common/modules/user/views/admin/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
'login_at:datetime',

[
'class' => 'backend\widgets\grid\ActionColumn',
'class' => 'yii\grid\ActionColumn',
'template' => '{update} {delete}'
]
],
Expand Down
3 changes: 3 additions & 0 deletions common/static/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ $.extend({
layer.close(index);
});
},
tips: function (message) {
layer.msg(message);
},
loading:function () {
return layer.load();
},
Expand Down
6 changes: 5 additions & 1 deletion common/static/yii.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,14 @@ yii = (function ($) {
data: $form.serialize(),
dataType: 'json',
success: function (res) {
if (res.status != undefined && res.status == 0) {
$.modal.error(res.message || '操作失败');
return;
}
if (!res.message) {
res.message = '操作成功';
}
$.modal.alert(res.message, 0, function () {
layer.msg(res.message, {time: 1000, icon:1}, function () {
if (refreshPjaxContainer) {
$.pjax.reload({container:'#' + refreshPjaxContainer});
}
Expand Down
85 changes: 0 additions & 85 deletions common/widgets/AlertPlus.php

This file was deleted.

5 changes: 2 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"minimum-stability": "stable",
"require": {
"php": ">=5.4.0",
"yiisoft/yii2": ">=2.0.8",
"yiisoft/yii2": "2.0.9",
"yiisoft/yii2-bootstrap": "*",
"yiisoft/yii2-swiftmailer": "*",
"kartik-v/yii2-widget-datetimepicker": "^1.4",
Expand All @@ -41,8 +41,7 @@
"fabpot/goutte": "^3.1",
"kartik-v/yii2-widget-select2": "*",
"udokmeci/yii2-beanstalk": "dev-master",
"hightman/xunsearch": "*@beta",
"bower-asset/pace": "^1.0"
"hightman/xunsearch": "*@beta"
},
"require-dev": {
"yiisoft/yii2-codeception": "*",
Expand Down
Loading

0 comments on commit b51dafa

Please sign in to comment.