|
@@ -2,6 +2,7 @@
|
|
|
|
|
|
namespace app\admin\controller\auth;
|
|
|
|
|
|
+use app\admin\model\AdminLog;
|
|
|
use app\common\controller\Backend;
|
|
|
use fast\Random;
|
|
|
use fast\Tree;
|
|
@@ -56,10 +57,11 @@ class Admin extends Backend
|
|
|
$params = $this->request->post("row/a");
|
|
|
if ($params)
|
|
|
{
|
|
|
- $params['salt'] = Random::basic(4);
|
|
|
+ $params['salt'] = Random::alnum();
|
|
|
$params['password'] = md5(md5($params['password']) . $params['salt']);
|
|
|
|
|
|
$admin = $this->model->create($params);
|
|
|
+ AdminLog::record(__('Add'), $this->model->getLastInsID());
|
|
|
$group = $this->request->post("group/a");
|
|
|
|
|
|
//过滤不允许的组别,避免越权
|
|
@@ -98,6 +100,7 @@ class Admin extends Backend
|
|
|
$params['password'] = md5(md5($params['password']) . $params['salt']);
|
|
|
}
|
|
|
$row->save($params);
|
|
|
+ AdminLog::record(__('Edit'), $ids);
|
|
|
|
|
|
// 先移除所有权限
|
|
|
model('AuthGroupAccess')->where('uid', $row->id)->delete();
|
|
@@ -137,15 +140,41 @@ class Admin extends Backend
|
|
|
$this->code = -1;
|
|
|
if ($ids)
|
|
|
{
|
|
|
- $count = $this->model->where('id', 'in', $ids)->delete();
|
|
|
- if ($count)
|
|
|
+ // 避免越权删除管理员
|
|
|
+ $childrenGroupIds = $this->childrenIds;
|
|
|
+ $adminList = $this->model->where('id', 'in', $ids)->where('id', 'in', function($query) use($childrenGroupIds)
|
|
|
+ {
|
|
|
+ $query->name('auth_group_access')->where('group_id', 'in', $childrenGroupIds)->field('uid');
|
|
|
+ })->select();
|
|
|
+ if ($adminList)
|
|
|
{
|
|
|
- model('AuthGroupAccess')->where('uid', 'in', $ids)->delete();
|
|
|
- $this->code = 1;
|
|
|
+ $deleteIds = [];
|
|
|
+ foreach ($adminList as $k => $v)
|
|
|
+ {
|
|
|
+ $deleteIds[] = $v->id;
|
|
|
+ }
|
|
|
+ $deleteIds = array_diff($deleteIds, [$this->auth->id]);
|
|
|
+ if ($deleteIds)
|
|
|
+ {
|
|
|
+ AdminLog::record(__('Del'), $deleteIds);
|
|
|
+ $this->model->destroy($deleteIds);
|
|
|
+ model('AuthGroupAccess')->where('uid', 'in', $deleteIds)->delete();
|
|
|
+ $this->code = 1;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 批量更新
|
|
|
+ * @internal
|
|
|
+ */
|
|
|
+ public function multi($ids = "")
|
|
|
+ {
|
|
|
+ // 管理员禁止批量操作
|
|
|
+ $this->code = -1;
|
|
|
+ }
|
|
|
+
|
|
|
}
|