From 868b54fb1aed1619083218666df2d0ab79aa9f47 Mon Sep 17 00:00:00 2001 From: hdm Date: Thu, 20 Apr 2023 15:34:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BD=95=E5=85=A5=E6=96=B0=E5=91=98=E5=B7=A5?= =?UTF-8?q?=E6=89=8B=E6=9C=BA=E5=8F=B7=E5=94=AF=E4=B8=80=EF=BC=8C=E9=82=AE?= =?UTF-8?q?=E7=AE=B1=E5=94=AF=E4=B8=80=E7=9A=84=E6=96=B9=E6=B3=95=E4=BC=98?= =?UTF-8?q?=E5=8C=96=EF=BC=8C=E6=94=AF=E6=8C=81=E9=80=9A=E8=BF=87=E6=89=8B?= =?UTF-8?q?=E6=9C=BA=E5=8F=B7=E7=A0=81+=E5=AF=86=E7=A0=81=E7=99=BB?= =?UTF-8?q?=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common.php | 2 +- app/home/controller/Login.php | 4 ++-- app/home/view/login/index.html | 2 +- app/user/validate/AdminCheck.php | 28 ++++++++++++++++++---------- 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/app/common.php b/app/common.php index a59390a..ec63e79 100644 --- a/app/common.php +++ b/app/common.php @@ -36,7 +36,7 @@ function get_system_config($name, $key = '') $config = get_cache('system_config' . $name); } else { $conf = Db::name('config')->where('name', $name)->find(); - if ($conf['content']) { + if (isset($conf['content'])) { $config = unserialize($conf['content']); } set_cache('system_config' . $name, $config); diff --git a/app/home/controller/Login.php b/app/home/controller/Login.php index 31c8f53..d82ff52 100644 --- a/app/home/controller/Login.php +++ b/app/home/controller/Login.php @@ -36,12 +36,12 @@ class Login if (empty($admin)) { $admin = Db::name('Admin')->where(['mobile' => $param['username']])->find(); if (empty($admin)) { - return to_assign(1, '用户名或密码错误'); + return to_assign(1, '用户名或手机号码错误'); } } $param['pwd'] = set_password($param['password'], $admin['salt']); if ($admin['pwd'] !== $param['pwd']) { - return to_assign(1, '用户名或密码错误'); + return to_assign(1, '用户或密码错误'); } if ($admin['status'] != 1) { return to_assign(1, '该用户禁止登录,请与管理者联系'); diff --git a/app/home/view/login/index.html b/app/home/view/login/index.html index faeda7a..d7ae3a1 100644 --- a/app/home/view/login/index.html +++ b/app/home/view/login/index.html @@ -47,7 +47,7 @@
- +
diff --git a/app/user/validate/AdminCheck.php b/app/user/validate/AdminCheck.php index a45eaac..bae92ce 100644 --- a/app/user/validate/AdminCheck.php +++ b/app/user/validate/AdminCheck.php @@ -13,17 +13,26 @@ class AdminCheck extends Validate { protected $regex = [ 'checkUser' => '/^[A-Za-z]{1}[A-Za-z0-9_-]{3,19}$/']; // 自定义验证规则 - protected function checkone($value,$rule,$data=[]) - { - $count = Db::name('Admin')->where([['username','=',$data['username']],['id','<>',$data['id']],['status','>=',0]])->count(); - return $count == 0 ? true : false; - } + protected function checkUnique($value, $rule, $data) + { + [$table, $field, $id] = explode(',', $rule); + $idField = $id ?: 'id'; + $idValue = $data[$idField] ?? null; + $map = [ + [$field, '=', $value], + ]; + if (!is_null($idValue)) { + $map[] = [$idField, '<>', $idValue]; + } + $map[] = ['status', '>=', 0]; + return !Db::name($table)->where($map)->count(); + } protected $rule = [ 'name' => 'require|chs', 'username' => 'require|regex:checkUser', - 'mobile' => 'require|mobile|unique:admin', - 'email' => 'require|email|unique:admin', + 'mobile' => 'require|mobile|checkUnique:Admin,mobile,id', + 'email' => 'require|email|checkUnique:Admin,email,id', 'reg_pwd' => 'require|min:6', 'did' => 'require', 'position_id' => 'require', @@ -40,13 +49,12 @@ class AdminCheck extends Validate 'name.chs' => '员工姓名只能是汉字', 'username.require' => '登录账号不能为空', 'username.regex' => '登录账号必须是以字母开头,只能包含字母数字下划线和减号,4到20位', - 'username.checkone' => '同样的登录账号已经存在,建议增加数字,如:xxx123', 'mobile.require' => '手机不能为空', 'mobile.mobile' => '手机格式错误', - 'mobile.unique' => '同样的手机号码已经存在,请检查一下是否被离职或者禁用员工占用', + 'mobile.checkUnique' => '同样的手机号码已经存在,请检查一下是否被离职或者禁用员工占用', 'email.require' => '邮箱不能为空', 'email.email' => '邮箱格式错误', - 'email.unique' => '同样的邮箱已经存在,请检查一下是否被离职或者禁用员工占用', + 'email.checkUnique' => '同样的邮箱已经存在,请检查一下是否被离职或者禁用员工占用', 'reg_pwd.require' => '密码不能为空', 'reg_pwd.min' => '密码至少要6个字符', 'did.require' => '请选择所在部门',