From 22c866253edca639b5e8e3122e5ff3d881df242c Mon Sep 17 00:00:00 2001 From: cxdbz Date: Thu, 18 Oct 2018 23:08:15 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=99=BB=E5=BD=95=E9=AA=8C?= =?UTF-8?q?=E8=AF=81=E3=80=81=E7=BC=96=E5=86=99=E7=AE=A1=E7=90=86=E5=91=98?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E3=80=81=E5=88=A0=E9=99=A4admin=E8=A1=A8miya?= =?UTF-8?q?o=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/controller/Error.php | 2 +- application/admin/controller/Index.php | 73 +++++++++++++++---- application/admin/model/Admin.php | 28 +++---- application/admin/view/index/create.html | 21 +++--- application/admin/view/index/index.html | 4 +- application/common/view/create.html | 4 + application/http/middleware/YanZheng.php | 4 +- application/index/view/index/index.html | 2 +- application/login/controller/Index.php | 32 ++++---- database/migrations/20181012140355_member.php | 2 +- route/admin.php | 13 ++++ 11 files changed, 121 insertions(+), 64 deletions(-) create mode 100644 route/admin.php diff --git a/application/admin/controller/Error.php b/application/admin/controller/Error.php index d94cb44d..23d823e6 100644 --- a/application/admin/controller/Error.php +++ b/application/admin/controller/Error.php @@ -7,5 +7,5 @@ use app\common\controller\BaseError; class Error extends BaseError { - // + } diff --git a/application/admin/controller/Index.php b/application/admin/controller/Index.php index 80f59a92..fbae6e43 100644 --- a/application/admin/controller/Index.php +++ b/application/admin/controller/Index.php @@ -6,6 +6,8 @@ namespace app\admin\controller; use app\common\controller\Base; // 引用用户数据模型 use app\admin\model\Admin; +// 引用加密类 +use WhiteHat101\Crypt\APR1_MD5; class Index extends Base { @@ -55,7 +57,8 @@ class Index extends Base //查询数据 $data = $admin - ->field('id,xingming,xingbie,username,phone,denglucishu,status,create_time') + ->field('id,xingming,sex,username,phone,denglucishu,status,create_time') + ->where('id','>','1') ->order([$order_field=>$order]) ->limit($limit_start,$limit_length) ->all(); @@ -65,7 +68,8 @@ class Index extends Base // 如果需要查询 if($search){ $data = $admin - ->field('id,xingming,xingbie,username,phone,denglucishu,status,create_time') + ->field('id,xingming,sex,username,phone,denglucishu,status,create_time') + ->where('id','>','1') ->order([$order_field=>$order]) ->limit($limit_start,$limit_length) ->where('username|xingming','like','%'.$search.'%') @@ -105,27 +109,64 @@ class Index extends Base // 保存管理员 public function save() { - $list = request()->post(); - dump($list); + + // 实例化管理员数据模型类 + $admin = new Admin(); + // 实例化加密类 + $md5 = new APR1_MD5(); + + // 获取表单数据 + $list = request()->only(['xingming','username','sex','shengri','phone','beizhu'],'post'); + + // 设置密码,默认为123456 + $list['password'] = $md5->hash('123456'); + + + $data = $admin->save($list); + + $msg = array(); + + if($data == 1) + { + $data =['msg'=>'添加成功']; + }else{ + $data =['msg'=>'数据处理错误']; + } + + + return json($data); } - /** - * 显示指定的资源 - * - * @param int $id - * @return \think\Response - */ + + public function test() + { + + + $md5 = new APR1_MD5(); + + $pas = $md5->hash('bz.023058213','aa'); + + dump($pas); + + $a = $md5->check('bz.023058213','$apr1$aa$T14IK9Aq/AUby29F34kwb.'); + + halt($a); + + } + + + + + // public function read($id) { // } - /** - * 显示编辑资源表单页. - * - * @param int $id - * @return \think\Response - */ + + + + // public function edit($id) { // diff --git a/application/admin/model/Admin.php b/application/admin/model/Admin.php index 685fe956..a8e75ee2 100644 --- a/application/admin/model/Admin.php +++ b/application/admin/model/Admin.php @@ -6,27 +6,21 @@ use think\Model; class Admin extends Model { - // 密码验证 - public function check( $username ,$password ) - { - // 验证用户名与密码是否匹配 - $list = $this - ->where('username',$username) - ->where('password',$password) - ->value('id'); - - return $list; - } - - // 获取密钥 - public function miyao($username) + // 获取密码 + public function password($username) { // 查询数据 - $miyao = $this + $pasW = $this ->where('username',$username) - ->value('miyao'); + ->value('password'); // 返回数据 - return $miyao; + return $pasW; + } + + // 生日修改器 + public function setShenriAttr($value) + { + return strtotime($value); } } diff --git a/application/admin/view/index/create.html b/application/admin/view/index/create.html index 1d56ae1e..d4fc1d39 100644 --- a/application/admin/view/index/create.html +++ b/application/admin/view/index/create.html @@ -1,6 +1,6 @@ {extend name="common@create" /} {block name="formaa"} -
+
@@ -17,15 +17,15 @@
- +
- +
- +
@@ -39,14 +39,14 @@
- +
- -

0/100

+ +

10/80

@@ -67,7 +67,7 @@ // 匹配帐号 $.validator.addMethod("ustr",function(value,element){ - var tel = /^[a-z][a-z-_]*$/; + var tel = /^[a-z][a-z0-9-_]*$/; return this.optional(element) || tel.test(value); }, "用户名由小写字母和 _ - 组成,首字符为字母"); @@ -89,9 +89,12 @@ shengri:{ dateISO:true }, - mobile:{ + phone:{ isMobile:true, }, + beizhu:{ + rangelength:[10,80] + }, }; {/block} \ No newline at end of file diff --git a/application/admin/view/index/index.html b/application/admin/view/index/index.html index a616fd93..97d4246f 100644 --- a/application/admin/view/index/index.html +++ b/application/admin/view/index/index.html @@ -21,7 +21,7 @@ 批量删除 - + 添加管理员 @@ -69,7 +69,7 @@ var mycolumns = [ { "data": "id" }, { "data": "xingming" }, - { "data": "xingbie" }, + { "data": "sex" }, { "data": "username" }, { "data": "phone" }, { "data": "denglucishu" }, diff --git a/application/common/view/create.html b/application/common/view/create.html index 2d69750c..177e06d5 100644 --- a/application/common/view/create.html +++ b/application/common/view/create.html @@ -67,7 +67,11 @@ $(function(){ { dataType: "json", success: function(data){ + layer.alert(data.msg); + }, + error: function(data){ + layer.alert('保存信息失败'); } } ); diff --git a/application/http/middleware/YanZheng.php b/application/http/middleware/YanZheng.php index 160ca260..a969e7d5 100644 --- a/application/http/middleware/YanZheng.php +++ b/application/http/middleware/YanZheng.php @@ -17,7 +17,7 @@ class YanZheng extends Controller $password = 0; // 如果用户没有登录直接跳转到登录页面 - if( session('?userid') ) + if( session('?username') ) { $username = session('username'); $password = session('password'); @@ -33,7 +33,7 @@ class YanZheng extends Controller // 检验用户名或密码是否正确 $yz = action('login/index/check',['username'=>$username,'password'=>$password]); if($yz == null){ - $this->error('请使用新密码登录'); + $this->error('请重新登录'); } diff --git a/application/index/view/index/index.html b/application/index/view/index/index.html index 103b25be..1198268e 100644 --- a/application/index/view/index/index.html +++ b/application/index/view/index/index.html @@ -132,7 +132,7 @@ diff --git a/application/login/controller/Index.php b/application/login/controller/Index.php index f838dcde..824fcb33 100644 --- a/application/login/controller/Index.php +++ b/application/login/controller/Index.php @@ -28,8 +28,7 @@ class Index extends Controller $admin = new admin(); // 实例化验证模型 $validate = new \app\login\validate\Yanzheng; - // 实例化加密类 - $md5 = new APR1_MD5(); + // 获取表单数据 $data = request()->only(['username','password']); @@ -41,14 +40,15 @@ class Index extends Controller $this->error($msg); } - // 重新计算密码 - $miyao = $admin->miyao('admin'); - $data['password'] = $md5->hash($miyao,$data['password']); + // + // $password = $admin->password($data['username']); + // $check = $md5->check($data['password'],$password); + // 验证用户名和密码 - $userid = $this->check($data['username'],$data['password']); + $check = $this->check($data['username'],$data['password']); - if($userid) + if($check) { // 设置cookie值 @@ -60,7 +60,7 @@ class Index extends Controller } // 将本次信息上传到服务器上 - $userinfo = $admin->get($userid); + $userinfo = $admin->getByUsername($data['username']); $userinfo->lastip = $userinfo->ip; $userinfo->ip = request()->host(); $userinfo->denglucishu = ['inc', 1]; @@ -82,25 +82,28 @@ class Index extends Controller // 已知密码进行验证 public function check($username,$password) { - //实例化类 + // 实例化管理员数据模型类 $admin = new admin(); + // 实例化加密类 + $md5 = new APR1_MD5(); + // 获取服务器密码 + $serpw = $admin->password($username); //验证密码 - $yz = $admin->check($username,$password); + $check = $md5->check($password,$serpw); - if($yz) + if($check) { // Session存值 session('username', $username); session('password', $password); - session('userid', $yz); }else{ // 清除cookie cookie(null, 'think_'); // 清除session(当前作用域) session(null); } - return $yz; + return $check; } @@ -137,8 +140,7 @@ class Index extends Controller $admin->id =1; $admin->xingming ='管理员'; $admin->username = 'admin'; - $admin->miyao = $md5->salt(); - $admin->password = $md5->hash($admin->miyao,'123'); + $admin->password = $md5->hash('123'); $data = $admin->save(); $msg[] = '、超级管理员信息初始化完成;'; }else{ diff --git a/database/migrations/20181012140355_member.php b/database/migrations/20181012140355_member.php index 5a6ff7bb..ed5fc1fb 100644 --- a/database/migrations/20181012140355_member.php +++ b/database/migrations/20181012140355_member.php @@ -38,7 +38,6 @@ class Member extends Migrator ->addColumn('shengri','integer',['limit'=>11,'null'=>true,'comment'=>'出生日期']) ->addColumn('username','string',['limit'=>12,'null'=>false,'comment'=>'用户帐号']) ->addColumn('password','string',['limit'=>37,'null'=>false,'comment'=>'登录密码']) - ->addColumn('miyao','string',['limit'=>8,'null'=>false,'comment'=>'密钥']) ->addColumn('phone','string',['limit'=>11,'null'=>true,'comment'=>'联系方式']) ->addColumn('denglucishu','integer',['limit'=>5,'default'=>0,'null'=>false,'comment'=>'登录次数']) ->addColumn('lastip','string',['limit'=>55,'default'=>'127.0.0.1','null'=>false,'comment'=>'最后一次登录IP']) @@ -49,6 +48,7 @@ class Member extends Migrator ->addColumn('create_time','integer',['limit'=>11,'default'=>'1539158918','null'=>false,'comment'=>'创建时间']) ->addColumn('update_time','integer',['limit'=>11,'default'=>'1539158918','null'=>false,'comment'=>'更新时间']) ->addColumn('delete_time','integer',['limit'=>11,'null'=>true,'comment'=>'删除时间']) + ->addColumn('beizhu','string',['limit'=>80,'null'=>true,'comment'=>'备注']) ->addIndex(array('username'), array('unique' => true)) ->create(); } diff --git a/route/admin.php b/route/admin.php new file mode 100644 index 00000000..94138262 --- /dev/null +++ b/route/admin.php @@ -0,0 +1,13 @@ + +// +---------------------------------------------------------------------- + +//系统设置路由 +Route::resource('admin','admin/index');