diff --git a/app/common.php b/app/common.php index 2cb55ba7..bbda1e12 100644 --- a/app/common.php +++ b/app/common.php @@ -177,3 +177,14 @@ $subject = $sbj->kaoshi(); return $subject; } + + + // 已知密码进行验证 + function loginCheck($inputPassword, $serverPassword) + { + // 实例化加密类 + $md5 = new \WhiteHat101\Crypt\APR1_MD5; + //验证密码 + $check = $md5->check($inputPassword, $serverPassword); + return $check; + } diff --git a/app/login/controller/Index.php b/app/login/controller/Index.php index fa2a721a..1cd14b08 100644 --- a/app/login/controller/Index.php +++ b/app/login/controller/Index.php @@ -1,10 +1,6 @@ only([ @@ -45,49 +45,44 @@ class Index ]); $validate = new \app\login\validate\Yanzheng; - $result = $validate->scene('fenliu')->check($list); + $result = $validate->scene('admin')->check($list); $msg = $validate->getError(); if(!$result){ return json(['msg' => $msg, 'val' => 0]); } - switch ($list['category']) { - case 'admin': - $data = $this->admin($list['username'], $list['password']); - break; + $yz = $this->yz($list['username'], $list['password']); - case 'teacher': - $data = $this->teacher($list['username'], $list['password']); - break; - - case 'student': - $data = $this->student($list['username'], $list['password']); - break; - - default: - $data = ['msg' => '用户身份丢失', 'val' => 1]; - break; + if($yz['val'] === 1) + { + // 获取服务器密码 + $admin = new \app\admin\model\Admin; + $userinfo = $admin::where('username', $list['username']) + ->where('status', 1) + ->field('id, lastip, username, ip, denglucishu, lasttime, thistime, password') + ->find(); + // 将本次信息上传到服务器上 + $userinfo->lastip = $userinfo->ip; + $userinfo->ip = request()->ip(); + $userinfo->denglucishu = ['inc', 1]; + $userinfo->lasttime = $userinfo->getData('thistime'); + $userinfo->thistime = time(); } - return json($data); + return json($yz); } - - // 管理员登录验证 - public function admin($username, $password) + // 获学生帐号密码信息 + public function yz($username, $password) { - session('onlineCategory', null); - session('user_id', null); - session('username', null); - session('password', null); // 获取服务器密码 - $userinfo = AD::where('username', $username) + $admin = new \app\admin\model\Admin; + $userinfo = $admin::where('username', $username) ->where('status', 1) ->field('id, lastip, username, ip, denglucishu, lasttime, thistime, password') ->find(); - - if($userinfo == null) + if ($userinfo == null) { // 验证结果; $data = ['msg' => '管理员帐号不存在或被禁用', 'val' => 0]; @@ -95,26 +90,17 @@ class Index } // 验证用户名和密码 - $check = $this->check($password, $userinfo->password); + $check = loginCheck($password, $userinfo->password); - if($check === true) + if ($check === true) { session('onlineCategory', 'admin'); session('user_id', $userinfo->id); session('username', $username); session('password', $password); - - // 将本次信息上传到服务器上 - $userinfo->lastip = $userinfo->ip; - $userinfo->ip = request()->ip(); - $userinfo->denglucishu = ['inc', 1]; - $userinfo->lasttime = $userinfo->getData('thistime'); - $userinfo->thistime = time(); - $userinfo->save(); - // 跳转到首页 $data = ['msg' => '验证成功', 'val' => 1, 'url' =>'\\']; - }else{ + } else { // 提示错误信息 $data = ['msg' => '用户名或密码错误', 'val' => 0]; } @@ -123,116 +109,6 @@ class Index } - // 管理员登录验证 - public function teacher($username, $password) - { - session('onlineCategory', null); - session('user_id', null); - session('username', null); - session('password', null); - // 获取服务器密码 - $tch = new \app\teacher\model\Teacher; - $userinfo = $tch::where('phone', $username) - ->where('status', 1) - ->field('id, lastip, phone, ip, denglucishu, lasttime, thistime, password') - ->find(); - - if($userinfo == null) - { - // 验证结果; - $data = ['msg' => '教师帐号不存在或被禁用', 'val' => 0]; - return $data; - } - - // 验证用户名和密码 - $check = $this->check($password, $userinfo->password); - - if($check === true) - { - session('onlineCategory', 'teacher'); - session('user_id', $userinfo->id); - session('username', $username); - session('password', $password); - - // 将本次信息上传到服务器上 - $userinfo->lastip = $userinfo->ip; - $userinfo->ip = request()->ip(); - $userinfo->denglucishu = ['inc', 1]; - $userinfo->lasttime = $userinfo->getData('thistime'); - $userinfo->thistime = time(); - $userinfo->save(); - - // 跳转到首页 - $data = ['msg' => '验证成功', 'val' => 1, 'url' => '/teacherSearchChengji/index/index']; - }else{ - // 提示错误信息 - $data = ['msg' => '用户名或密码错误', 'val' => 0]; - } - - return $data; - } - - // 管理员登录验证 - public function student($username, $password) - { - session('onlineCategory', null); - session('user_id', null); - session('username', null); - session('password', null); - // 获取服务器密码 - $stu = new \app\student\model\Student; - $userinfo = $stu::where('shenfenzhenghao', $username) - ->where('status', 1) - ->field('id, lastip, shenfenzhenghao, ip, denglucishu, lasttime, thistime, password') - ->find(); - - if($userinfo == null) - { - // 验证结果; - $data = ['msg' => '学生帐号不存在或被禁用', 'val' => 0]; - return $data; - } - - // 验证用户名和密码 - $check = $this->check($password, $userinfo->password); - - if($check === true) - { - session('onlineCategory', 'student'); - session('user_id', $userinfo->id); - session('username', $username); - session('password', $password); - - // 将本次信息上传到服务器上 - $userinfo->lastip = $userinfo->ip; - $userinfo->ip = request()->ip(); - $userinfo->denglucishu = ['inc', 1]; - $userinfo->lasttime = $userinfo->getData('thistime'); - $userinfo->thistime = time(); - $userinfo->save(); - - // 跳转到首页 - $data = ['msg' => '验证成功', 'val' => 1, 'url' => '/studentSearchChengji/index/index']; - }else{ - // 提示错误信息 - $data = ['msg' => '用户名或密码错误', 'val' => 0]; - } - - return $data; - } - - - // 已知密码进行验证 - public function check($inputPassword, $serverPassword) - { - // 实例化加密类 - $md5 = new APR1_MD5(); - //验证密码 - $check = $md5->check($inputPassword, $serverPassword); - return $check; - } - - // 系统更新日志 public function shangmaLog() { diff --git a/app/login/controller/Student.php b/app/login/controller/Student.php new file mode 100644 index 00000000..68d496e7 --- /dev/null +++ b/app/login/controller/Student.php @@ -0,0 +1,86 @@ +only([ + 'username' + ,'password' + ,'category' + ]); + + $validate = new \app\login\validate\Yanzheng; + $result = $validate->scene('admin')->check($list); + $msg = $validate->getError(); + if(!$result){ + return json(['msg' => $msg, 'val' => 0]); + } + + $yz = $this->yz($list['username'], $list['password']); + + if($yz['val'] === 1) + { + // 获取服务器密码 + $stu = new \app\student\model\Student; + $userinfo = $stu::where('shenfenzhenghao', $list['username']) + ->where('status', 1) + ->field('id, lastip, shenfenzhenghao, ip, denglucishu, lasttime, thistime, password') + ->find(); + // 将本次信息上传到服务器上 + $userinfo->lastip = $userinfo->ip; + $userinfo->ip = request()->ip(); + $userinfo->denglucishu = ['inc', 1]; + $userinfo->lasttime = $userinfo->getData('thistime'); + $userinfo->thistime = time(); + } + + return json($yz); + } + + + // 获学生帐号密码信息 + public function yz($username, $password) + { + // 获取服务器密码 + $stu = new \app\student\model\Student; + $userinfo = $stu::where('shenfenzhenghao', $username) + ->where('status', 1) + ->field('id, lastip, shenfenzhenghao, ip, denglucishu, lasttime, thistime, password') + ->find(); + if ($userinfo == null) + { + // 验证结果; + $data = ['msg' => '学生帐号不存在或被禁用', 'val' => 0]; + return $data; + } + + // 验证用户名和密码 + $check = loginCheck($password, $userinfo->password); + + if ($check === true) + { + session('onlineCategory', 'student'); + session('user_id', $userinfo->id); + session('username', $username); + session('password', $password); + // 跳转到首页 + $data = ['msg' => '验证成功', 'val' => 1, 'url' =>'\\studentSearchChengji\\index\\index']; + } else { + // 提示错误信息 + $data = ['msg' => '用户名或密码错误', 'val' => 0]; + } + + return $data; + } + +} diff --git a/app/login/controller/Teacher.php b/app/login/controller/Teacher.php new file mode 100644 index 00000000..c5993291 --- /dev/null +++ b/app/login/controller/Teacher.php @@ -0,0 +1,90 @@ +only([ + 'username' + ,'password' + ,'category' + ]); + + + $validate = new \app\login\validate\Yanzheng; + $result = $validate->scene('admin')->check($list); + $msg = $validate->getError(); + if(!$result){ + return json(['msg' => $msg, 'val' => 0]); + } + + $yz = $this->yz($list['username'], $list['password']); + + if($yz['val'] === 1) + { + // 获取服务器密码 + $ter = new \app\teacher\model\Teacher; + $userinfo = $ter::where('phone', $list['username']) + ->where('status', 1) + ->field('id, lastip, phone, ip, denglucishu, lasttime, thistime, password') + ->find(); + // 将本次信息上传到服务器上 + $userinfo->lastip = $userinfo->ip; + $userinfo->ip = request()->ip(); + $userinfo->denglucishu = ['inc', 1]; + $userinfo->lasttime = $userinfo->getData('thistime'); + $userinfo->thistime = time(); + } + + return json($yz); + } + + + // 获学生帐号密码信息 + public function yz($username, $password) + { + // 获取服务器密码 + $ter = new \app\teacher\model\Teacher; + $userinfo = $ter::where('phone', $username) + ->where('status', 1) + ->field('id, lastip, phone, ip, denglucishu, lasttime, thistime, password') + ->find(); + if ($userinfo == null) + { + // 验证结果; + $data = ['msg' => '教师帐号不存在或被禁用', 'val' => 0]; + return $data; + } + + // 验证用户名和密码 + $check = loginCheck($password, $userinfo->password); + + if ($check === true) + { + session('onlineCategory', 'teacher'); + session('user_id', $userinfo->id); + session('username', $username); + session('password', $password); + // 跳转到首页 + $data = ['msg' => '验证成功', 'val' => 1, 'url' =>'\\teacherSearchChengji\\index\\index']; + } else { + // 提示错误信息 + $data = ['msg' => '用户名或密码错误', 'val' => 0]; + } + + return $data; + } + +} diff --git a/app/login/route/login.php b/app/login/route/login.php index 94d91621..8cbc3480 100644 --- a/app/login/route/login.php +++ b/app/login/route/login.php @@ -13,22 +13,20 @@ use think\facade\Route; // 系统设置systembase Route::group('', function () { - Route::rule('','Index/index','get'); - Route::rule('','Index/yanchengdenglu','post'); - Route::rule('log','Index/shangmaLog','get'); # 配置更新 - Route::rule('err','Index/myerror','get'); //错误页 - Route::rule('weihu','Index/weihu','get'); //错误页 + Route::rule('', 'Index/index', 'get'); + Route::rule('', 'Index/login', 'post'); + Route::rule('log', 'Index/shangmaLog', 'get'); # 配置更新 + Route::rule('err', 'Index/myerror', 'get'); //错误页 + Route::rule('weihu', 'Index/weihu', 'get'); //错误页 }); -// // 学生查询成绩登录 -// Route::group('student', function () { -// Route::rule('','Student/index','get'); -// Route::rule('','Student/yanzheng','post'); -// }); +// 学生查询成绩登录 +Route::group('student', function () { + Route::rule('', 'Student/login', 'post'); +}); -// // 学生查询成绩登录 -// Route::group('teacher', function () { -// Route::rule('','Teacher/index','get'); -// Route::rule('','Teacher/yanzheng','post'); -// }); +// 学生查询成绩登录 +Route::group('teacher', function () { + Route::rule('', 'Teacher/login', 'post'); +}); diff --git a/app/login/view/index/index.html b/app/login/view/index/index.html index 7d723a66..f9a74760 100644 --- a/app/login/view/index/index.html +++ b/app/login/view/index/index.html @@ -34,7 +34,7 @@
{$list['webtitle']} {$list['version']}
-
+
@@ -71,6 +71,23 @@ }, }) + var url = '/login'; + + form.on('radio(category)', function(data){ + switch(data.value){ + case 'admin': + url = '/login'; + break; + case 'teacher': + url = '/login/teacher'; + break; + case 'student': + url = '/login/student'; + break; + }; + }); + + //监听提交 form.on('submit(login)', function(data){ yz = slider.isOk(); @@ -79,8 +96,24 @@ layer.msg("请先通过滑块验证"); return false; } + formval = data.field; + switch(formval.category){ + case 'admin': + url = '/login'; + break; + case 'teacher': + url = '/login/teacher'; + break; + case 'student': + url = '/login/student'; + break; + default: + layer.msg('请先选择登录身份'); + return false; + }; + $.ajax({ - url:"/login", + url:url, type:'POST', async: true, data:data.field, diff --git a/app/middleware/Login.php b/app/middleware/Login.php index 98830501..9d73a5ac 100644 --- a/app/middleware/Login.php +++ b/app/middleware/Login.php @@ -18,17 +18,16 @@ class Login switch ($category) { case 'admin': $yz = new \app\login\controller\Index; - $yz = $yz->admin(session('username'), session('password')); + $yz = $yz->yz(session('username'), session('password')); break; case 'teacher': - $yz = new \app\login\controller\Index; - $yz = $yz->teacher(session('username'), session('password')); + $yz = new \app\login\controller\Teacher; + $yz = $yz->yz(session('username'), session('password')); break; case 'student': - $yz = new \app\login\controller\Index; - $yz = $yz->student(session('username'), session('password')); + $yz = new \app\login\controller\Student; + $yz = $yz->yz(session('username'), session('password')); break; - default: \app\facade\OnLine::jump('/login', '请选择用户角色'); break;