diff --git a/app/home/common.php b/app/home/common.php index 523efa4..a6a951c 100644 --- a/app/home/common.php +++ b/app/home/common.php @@ -267,31 +267,32 @@ function check_auth($rule, $uid) */ function add_log($type, $param_id = '', $param = []) { - $request = get_params(); - switch ($type) { + $action = '未知操作'; + switch ($type) { case 'login': - $title = '登录'; + $action = '登录'; break; case 'upload': - $title = '上传'; + $action = '上传'; break; case 'add': - $title = '新增'; + $action = '新增'; break; case 'edit': - $title = '编辑'; + $action = '编辑'; break; case 'view': - $title = '查看'; + $action = '查看'; break; case 'delete': - $title = '删除'; + $action = '删除'; break; case 'check': - $title = '审核'; + $action = '审核'; break; - default: - $title = '未知'; + break; + case 'reset': + $action = '重新设置'; break; } if ($type == 'login') { @@ -304,15 +305,23 @@ function add_log($type, $param_id = '', $param = []) $data['uid'] = $login_admin['id']; $data['name'] = $login_admin['name']; $data['type'] = $type; + $data['action'] = $action; $data['param_id'] = $param_id; $data['param'] = json_encode($param); $data['module'] = \think\facade\App::initialize()->http->getName(); $data['controller'] = strtolower(app('request')->controller()); $data['function'] = app('request')->action(); $parameter = $data['module'] . '/' . $data['controller'] . '/' . $data['function']; - $data['rule_menu'] = $parameter; - $data['title'] = Db::name('AdminRule')->where(array('src' => $parameter))->value('title') ?? $title; - $content = $login_admin['name'] . '在' . date('Y-m-d H:i:s') . '执行了' . $data['title'] . '操作'; + $rule_menu = Db::name('AdminRule')->where(array('src' => $parameter))->find(); + if($rule_menu){ + $data['title'] = $rule_menu['title']; + $data['subject'] = $rule_menu['name']; + } + else{ + $data['title'] = ''; + $data['subject'] ='系统'; + } + $content = $login_admin['name'] . '在' . date('Y-m-d H:i:s') . $data['action'] . '了' . $data['subject']; $data['content'] = $content; $data['ip'] = app('request')->ip(); $data['create_time'] = time(); diff --git a/app/home/controller/Admin.php b/app/home/controller/Admin.php index b3f1c1e..dea24b8 100644 --- a/app/home/controller/Admin.php +++ b/app/home/controller/Admin.php @@ -274,7 +274,7 @@ class Admin extends BaseController } $rows = empty($param['limit']) ? get_config(app . page_size) : $param['limit']; $content = DB::name('AdminLog') - ->field("id,uid,name,title,content,rule_menu,ip,param_id,param,FROM_UNIXTIME(create_time,'%Y-%m-%d %H:%i:%s') create_time") + ->field("id,uid,name,action,title,content,rule_menu,ip,param_id,param,FROM_UNIXTIME(create_time,'%Y-%m-%d %H:%i:%s') create_time") ->order('create_time desc') ->where($where) ->paginate($rows, false, ['query' => $param]); diff --git a/app/home/controller/Api.php b/app/home/controller/Api.php index 3306f46..f03349a 100644 --- a/app/home/controller/Api.php +++ b/app/home/controller/Api.php @@ -225,37 +225,54 @@ class Api extends BaseController //修改个人信息 public function edit_personal() { - return view('admin/edit_personal', [ - 'admin' => get_admin($this->uid), - ]); - } - - //保存个人信息修改 - public function personal_submit() - { - if (request()->isAjax()) { + if (request()->isAjax()) { $param = get_params(); - try { - validate(AdminCheck::class)->scene('editPersonal')->check($param); - } catch (ValidateException $e) { - // 验证失败 输出错误信息 - return to_assign(1, $e->getError()); - } - unset($param['username']); $uid = $this->uid; Db::name('Admin')->where(['id' => $uid])->strict(false)->field(true)->update($param); $session_admin = get_config('app.session_admin'); Session::set($session_admin, Db::name('admin')->find($uid)); return to_assign(); } + else{ + return view('admin/edit_personal', [ + 'admin' => get_admin($this->uid), + ]); + } } //修改密码 public function edit_password() { - return view('admin/edit_password', [ - 'admin' => get_admin($this->uid), - ]); + if (request()->isAjax()) { + $param = get_params(); + try { + validate(AdminCheck::class)->scene('editPwd')->check($param); + } catch (ValidateException $e) { + // 验证失败 输出错误信息 + return to_assign(1, $e->getError()); + } + $uid = $this->uid; + + $admin = Db::name('Admin')->where(['id' => $uid])->find(); + $old_psw = set_password($param['old_pwd'], $admin['salt']); + if ($admin['pwd'] != $old_psw) { + return to_assign(1, '旧密码错误'); + } + + $salt = set_salt(20); + $param['pwd'] = set_password($param['pwd'], $salt); + $param['reg_pwd'] = ''; + $param['update_time'] = time(); + Db::name('Admin')->where(['id' => $uid])->strict(false)->field(true)->update($param); + $session_admin = get_config('app.session_admin'); + Session::set($session_admin, Db::name('admin')->find($uid)); + return to_assign(); + } + else{ + return view('admin/edit_password', [ + 'admin' => get_admin($this->uid), + ]); + } } //保存密码修改 diff --git a/app/home/model/AdminLog.php b/app/home/model/AdminLog.php index 59e4b6a..4a1e994 100644 --- a/app/home/model/AdminLog.php +++ b/app/home/model/AdminLog.php @@ -36,14 +36,7 @@ class AdminLog extends Model foreach ($content as $k => $v) { $data = $v; $param_array = json_decode($v['param'], true); - $name = ''; - if (!empty($param_array['name'])) { - $name = ':' . $param_array['name']; - } - if (!empty($param_array['title'])) { - $name = ':' . $param_array['title']; - } - $data['content'] = $v['content'] . $name; + $data['content'] = $v['content']; $data['times'] = time_trans($v['create_time']); $content->offsetSet($k, $data); } diff --git a/app/home/validate/AdminCheck.php b/app/home/validate/AdminCheck.php index 9d12f77..f1ba7a6 100644 --- a/app/home/validate/AdminCheck.php +++ b/app/home/validate/AdminCheck.php @@ -23,9 +23,9 @@ class AdminCheck extends Validate 'type' => 'require', 'entry_time' => 'require', 'id' => 'require', + 'pwd' => 'require|min:6|confirm', 'status' => 'require|checkStatus:-1,1', 'old_pwd' => 'require|different:pwd', - 'edit_pwd' => 'min:6|confirm', ]; protected $message = [ @@ -45,9 +45,8 @@ class AdminCheck extends Validate 'entry_time.require' => '请选择入职时间', 'id.require' => '缺少更新条件', 'pwd.require' => '密码不能为空', - 'pwd.min' => '密码至少要6个字符', - 'edit_pwd.min' => '密码至少要6个字符', - 'edit_pwd.confirm' => '两次密码不一致', + 'pwd.min' => '密码至少要6个字符', + 'pwd.confirm' => '两次密码不一致', 'old_pwd.require' => '请提供旧密码', 'old_pwd.different' => '新密码不能和旧密码一样', ]; @@ -55,8 +54,7 @@ class AdminCheck extends Validate protected $scene = [ 'add' => ['name', 'username', 'mobile','reg_pwd', 'did', 'position_id', 'type', 'entry_time'], 'edit' => ['name', 'username', 'mobile', 'did', 'position_id', 'entry_time', 'id'], - 'editPersonal' => ['mobile', 'name', 'id'], - 'editpwd' => ['old_pwd', 'pwd', 'id'], + 'editPwd' => ['old_pwd', 'pwd'], ]; } diff --git a/app/home/view/admin/edit_password.html b/app/home/view/admin/edit_password.html index 1869fb5..d56aeff 100644 --- a/app/home/view/admin/edit_password.html +++ b/app/home/view/admin/edit_password.html @@ -5,13 +5,12 @@
用户名 * | -旧密码* | + | 用户名 | +{$admin.username} | |
新密码 * | @@ -42,7 +41,7 @@ //监听提交 form.on('submit(webform)', function (data) { $.ajax({ - url: "{:url('home/api/personal_submit')}", + url: "{:url('home/api/edit_password')}", type: 'post', data: data.field, success: function (e) { diff --git a/app/home/view/admin/edit_personal.html b/app/home/view/admin/edit_personal.html index 5b30864..c36ecdc 100644 --- a/app/home/view/admin/edit_personal.html +++ b/app/home/view/admin/edit_personal.html @@ -2,16 +2,17 @@ {block name="body"}