diff --git a/application/admin/controller/AuthGroup.php b/application/admin/controller/AuthGroup.php new file mode 100644 index 00000000..04f5bbaa --- /dev/null +++ b/application/admin/controller/AuthGroup.php @@ -0,0 +1,85 @@ +where('id','<>',1)->count(); // 设置要给模板赋值的信息 @@ -30,6 +29,7 @@ class Index extends Base // 渲染模板 return $this->fetch(); + // 获取记录总数 } @@ -116,6 +116,9 @@ class Index extends Base $admin = new Admin(); // 实例化加密类 $md5 = new APR1_MD5(); + // 实例化验证模型 + $validate = new \app\admin\validate\Admin; + // 获取表单数据 $list = request()->only(['xingming','username','sex','shengri','phone','beizhu'],'post'); @@ -124,6 +127,17 @@ class Index extends Base $list['password'] = $md5->hash('123456'); + // 验证表单数据 + $result = $validate->check($list); + $msg = $validate->getError(); + + + // 如果验证不通过则停止保存 + if(!$result){ + return json(['msg'=>$msg,'val'=>0]);; + } + + // 保存数据 $data = $admin->save($list); $msg = array(); @@ -133,8 +147,10 @@ class Index extends Base // 返回信息 return json($data); + } - + + // 读取用户信息 @@ -167,6 +183,7 @@ class Index extends Base ->field('id,username,xingming,sex,shengri,phone,beizhu') ->get($id); + $this->assign('list',$list); return $this->fetch(); @@ -178,10 +195,22 @@ class Index extends Base { // 实例化管理员数据模型类 $admin = new Admin(); + // 实例化验证模型 + $validate = new \app\admin\validate\Admin; // 获取表单数据 $list = request()->put(); + // 验证表单数据 + $result = $validate->check($list); + $msg = $validate->getError(); + + // 如果验证不通过则停止保存 + if(!$result){ + return json(['msg'=>$msg,'val'=>0]);; + } + + $data = $admin->save($list,['id'=>$id]); // 根据更新结果设置返回提示信息 @@ -266,7 +295,7 @@ class Index extends Base $data = $list->save(); // 根据更新结果设置返回提示信息 - $data ? $data=['msg'=>'密码重置成功','val'=>1] : $data=['msg'=>'数据处理错误','val'=>0]; + $data ? $data=['msg'=>'密码已经重置为:
123456','val'=>1] : $data=['msg'=>'数据处理错误','val'=>0]; // 返回信息 return json($data); diff --git a/application/admin/model/Admin.php b/application/admin/model/Admin.php index 840636bf..e3546480 100644 --- a/application/admin/model/Admin.php +++ b/application/admin/model/Admin.php @@ -2,7 +2,6 @@ namespace app\admin\model; -use think\Model; // 引用用户数据模型 use app\common\model\Base; diff --git a/application/admin/model/AuthGroup.php b/application/admin/model/AuthGroup.php new file mode 100644 index 00000000..8fabc409 --- /dev/null +++ b/application/admin/model/AuthGroup.php @@ -0,0 +1,11 @@ + 'require|chs|length:2,6', - 'username' => ['require','ustr'=>'/^[\u4e00-\u9fa5]*$/'] - 'shengri' => 'date', - 'xingbie' => 'in:0,1,2', - 'phone' => 'mobile', - 'beizhu' => 'max:80', + 'xingming|用户姓名' => 'require|chs|length:2,6', + 'username|帐号' => ['require','uset'=>'/^[a-z][a-z0-9-_]*$/'], + 'shengri|出生日期' => 'date', + 'xingbie|性别' => 'in:0,1,2', + 'phone|手机' => 'mobile', + 'beizhu|备注' => 'max:80', ]; /** diff --git a/application/admin/view/index/create.html b/application/admin/view/index/create.html index 5e7e54f9..d826f386 100644 --- a/application/admin/view/index/create.html +++ b/application/admin/view/index/create.html @@ -17,7 +17,7 @@
- +
@@ -25,7 +25,7 @@
- +
diff --git a/application/admin/view/index/edit.html b/application/admin/view/index/edit.html index ff2f397f..c89bb80c 100644 --- a/application/admin/view/index/edit.html +++ b/application/admin/view/index/edit.html @@ -17,15 +17,15 @@
- +
- +
- +
diff --git a/application/common/view/list.html b/application/common/view/list.html index ba088ce1..ed505100 100644 --- a/application/common/view/list.html +++ b/application/common/view/list.html @@ -266,7 +266,7 @@ function resetpw(obj,id){ url: "/resetpassword/" + id, dataType: 'json', success: function(data){ - layer.alert(data.msg,{icon:1,time:1000}); + layer.alert(data.msg,{icon:1,time:3000}); }, error:function(data) { layer.alert('操作失败');