diff --git a/app/Luru/controller/Index.php b/app/Luru/controller/Index.php index 7f919260..b93c71a7 100644 --- a/app/Luru/controller/Index.php +++ b/app/Luru/controller/Index.php @@ -30,18 +30,16 @@ class Index extends BaseController { $this->middleware = [ 'online' - ,'terlogin' + ,'login' ]; - $this->luruTeacherId = session('teacher.userid'); - }else{ $this->middleware = [ 'online' ,'login' ,'auth' ]; - $this->luruTeacherId = session('admin.userid'); } + $this->luruTeacherId = session('user_id'); } // 成绩列表 diff --git a/app/base/controller/AdminBase.php b/app/base/controller/AdminBase.php index 53e00cb8..3ca65b09 100644 --- a/app/base/controller/AdminBase.php +++ b/app/base/controller/AdminBase.php @@ -19,4 +19,14 @@ abstract class AdminBase extends BaseController ,'login' ,'auth' ]; + + // 初始化变量 + protected function initialize() + { + $this->online = session('onlineCategory'); + if($this->online != 'admin') + { + \app\facade\OnLine::jump('/login', '请使用管理员帐号登录'); + } + } } diff --git a/app/base/controller/StudentSearchBase.php b/app/base/controller/StudentSearchBase.php index 82a4abc5..bf8c084c 100644 --- a/app/base/controller/StudentSearchBase.php +++ b/app/base/controller/StudentSearchBase.php @@ -15,6 +15,16 @@ abstract class StudentSearchBase extends BaseController */ protected $middleware = [ 'online' - ,'stulogin' + ,'login' ]; + + // 初始化变量 + protected function initialize() + { + $this->online = session('onlineCategory'); + if($this->online != 'student') + { + \app\facade\OnLine::jump('/login', '请使用学生帐号登录'); + } + } } diff --git a/app/base/controller/TeacherSearchBase.php b/app/base/controller/TeacherSearchBase.php index df17c772..84768cf5 100644 --- a/app/base/controller/TeacherSearchBase.php +++ b/app/base/controller/TeacherSearchBase.php @@ -15,6 +15,16 @@ abstract class TeacherSearchBase extends BaseController */ protected $middleware = [ 'online' - ,'terlogin' + ,'login' ]; + + // 初始化变量 + protected function initialize() + { + $this->online = session('onlineCategory'); + if($this->online != 'teacher') + { + \app\facade\OnLine::jump('/login', '登录超时啦~'); + } + } } diff --git a/app/index/controller/Index.php b/app/index/controller/Index.php index 8752974b..0de823fb 100644 --- a/app/index/controller/Index.php +++ b/app/index/controller/Index.php @@ -18,9 +18,9 @@ class Index extends AdminBase $list['webtitle'] = config('shangma.webtitle'); # 系统名称 $list['version'] = config('shangma.version'); # 版本号 $ad = new \app\admin\model\Admin; # 获取用户姓名 - $list->xingming = $ad->where('id', session('admin.userid'))->value('xingming'); + $list->xingming = $ad->where('id', session('user_id'))->value('xingming'); $auth = new \app\admin\model\AuthRule; # 菜单 - $menu = $auth->menu(session('admin.userid')); + $menu = $auth->menu(session('user_id')); $list['menu'] = $menu; // 模版赋值 @@ -48,9 +48,9 @@ class Index extends AdminBase // 查询用户姓名及用户拥有的权限 $admin = new \app\admin\model\Admin; - $list['xingming'] = $admin->where('id',session('admin.userid')) + $list['xingming'] = $admin->where('id',session('user_id')) ->value('xingming'); - $list['group'] = $admin->getGroupnames(session('admin.userid')); + $list['group'] = $admin->getGroupnames(session('user_id')); $list['server'] = request()->server(); // 获取系统版本号 diff --git a/app/login/controller/Index.php b/app/login/controller/Index.php index 3e4ab2e7..d1873b33 100644 --- a/app/login/controller/Index.php +++ b/app/login/controller/Index.php @@ -53,15 +53,15 @@ class Index switch ($list['category']) { case 'admin': - $data = $this->admin($list); + $data = $this->admin($list['username'], $list['password']); break; case 'teacher': - $data = $this->teacher($list); + $data = $this->teacher($list['username'], $list['password']); break; case 'student': - $data = $this->student($list); + $data = $this->student($list['username'], $list['password']); break; default: @@ -74,33 +74,32 @@ class Index - // 登录验证 - public function admin($list) + // 管理员登录验证 + public function admin($username, $password) { + session(null); // 获取服务器密码 - $userinfo = AD::where('username', $list['username']) - ->where('val', 1) + $userinfo = AD::where('username', $username) + ->where('status', 1) ->field('id, lastip, username, ip, denglucishu, lasttime, thistime, password') ->find(); if($userinfo == null) { - // 清除session(当前作用域) - session(null); // 验证结果; $data = ['msg' => '管理员帐号不存在或被禁用', 'val' => 0]; - return json($data); + return $data; } - // 验证用户名和密码 - $check = $this->check($list['password'], $userinfo->password); + $check = $this->check($password, $userinfo->password); - if($check['val'] === 1) + if($check === true) { - session(null); session('onlineCategory', 'admin'); session('user_id', $userinfo->id); + session('username', $username); + session('password', $password); // 将本次信息上传到服务器上 $userinfo->lastip = $userinfo->ip; @@ -111,42 +110,117 @@ class Index $userinfo->save(); // 跳转到首页 - $data = ['msg' => '验证成功', 'val' => 1]; + $data = ['msg' => '验证成功', 'val' => 1, 'url' =>'\\']; }else{ // 提示错误信息 - $data = ['msg' => $check['msg'], 'val' => 0]; + $data = ['msg' => '用户名或密码错误', 'val' => 0]; } - return json($data); + return $data; + } + + + // 管理员登录验证 + public function teacher($username, $password) + { + session(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(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($srcfrom) + public function check($inputPassword, $serverPassword) { - $src = [ - 'username' => '' - ,'password' => '' - ,'onlineCategory' => '' - ,'user_id' => '' - ]; - $src = array_cover($srcfrom, $src); - // 实例化加密类 $md5 = new APR1_MD5(); - //验证密码 $check = $md5->check($inputPassword, $serverPassword); - - if($check) - { - session('username', $username); - session('password', $password); - $data = ['msg' => '验证成功', 'val' => 1]; - }else{ - $data = ['msg' => '用户名或密码错误', 'val' => 0]; - } - return $data; + return $check; } diff --git a/app/login/controller/Student.php b/app/login/controller/Student.php deleted file mode 100644 index 17c88636..00000000 --- a/app/login/controller/Student.php +++ /dev/null @@ -1,141 +0,0 @@ -isMobile(); - // 清除cookie - cookie('userid', null); - cookie('username', null); - cookie('password', null); - // 清除session(当前作用域) - session(null); - - // 获取系统名称和版本号 - $list['webtitle'] = Config::get('shangma.webtitle'); - $list['version'] = Config::get('shangma.version'); - $list['mobile'] = $mobile; - - View::assign('list',$list); - - // 渲染输出 - return View::fetch(); - } - - - // 成绩验证 - public function yanzheng() - { - // 获取表单数据 - $data = request()->only(['username','password','online']); - - // 验证表单数据 - try { - // 实例化验证模型 - $validate = new \app\login\validate\Yanzheng; - validate(Yanzheng::class)->scene('student')->check($data); - } catch (ValidateException $e) { - // 验证失败 输出错误信息 - $data=['msg'=>$e->getError(),'status'=>0]; - return json($data); - } - - // 验证用户名和密码 - $check = $this->check($data['username'],$data['password']); - - if($check['status']==1) - { - // 设置cookie值 - if( request()->post('online') == true ) - { - // 设置 - cookie('userid', session('userid')); - cookie('username', $data['username']); - cookie('password', $data['password']); - } - - // 将本次信息上传到服务器上 - $userinfo = stu::where('shenfenzhenghao',$data['username']) - ->field('lastip,ip,denglucishu,lasttime,thistime') - ->find(); - $userinfo->lastip = $userinfo->ip; - $userinfo->ip = request()->ip(); - $userinfo->denglucishu = ['inc', 1]; - $userinfo->lasttime = $userinfo->getData('thistime'); - $userinfo->thistime = time(); - $userinfo->save(); - - // 跳转到首页 - $data=['msg'=>'验证成功','status'=>1]; - }else{ - // 提示错误信息 - $data=['msg'=>$check['msg'],'status'=>0]; - } - - return json($data); - } - - - // 已知密码进行验证 - public function check($username,$password) - { - // 实例化加密类 - $md5 = new APR1_MD5(); - - // 获取服务器密码 - $userinfo = stu::where('shenfenzhenghao', $username)->where('status', 1)->find(); - - if($userinfo == null) - { - // 清除session(当前作用域) - session(null); - // 验证结果; - $data=['msg'=>'学生不存在或被禁用','status'=>0]; - return $data; - } - - //验证密码 - $check = $md5->check($password,$userinfo->password); - - if($check) - { - session('student', null); - session('onlineCategory', 'student'); - session('student.userid', $userinfo->id); - session('student.username', $username); - session('student.password', $password); - - $data=['msg'=>'验证成功','status'=>1]; - }else{ - // 清除cookie - cookie('userid', null); - cookie('username', null); - cookie('password', null); - // 清除session(当前作用域) - session(null); - $data=['msg'=>'学生身份证号或密码错误','status'=>0]; - } - return $data; - } -} diff --git a/app/login/controller/Teacher.php b/app/login/controller/Teacher.php deleted file mode 100644 index 47633375..00000000 --- a/app/login/controller/Teacher.php +++ /dev/null @@ -1,140 +0,0 @@ -isMobile(); - // 清除cookie - cookie('userid', null); - cookie('username', null); - cookie('password', null); - // 清除session(当前作用域) - session(null); - - // 获取系统名称和版本号 - $list['webtitle'] = Config::get('shangma.webtitle'); - $list['version'] = Config::get('shangma.version'); - $list['mobile'] = $mobile; - - View::assign('list',$list); - - // 渲染输出 - return View::fetch(); - } - - - // 成绩验证 - public function yanzheng() - { - // 获取表单数据 - $data = request()->only(['username','password','online']); - - // 验证表单数据 - try { - // 实例化验证模型 - $validate = new \app\login\validate\Yanzheng; - validate(Yanzheng::class)->scene('admin')->check($data); - } catch (ValidateException $e) { - // 验证失败 输出错误信息 - $data=['msg'=>$e->getError(),'status'=>0]; - return json($data); - } - - // 验证用户名和密码 - $check = $this->check($data['username'],$data['password']); - - if($check['status']==1) - { - // 设置cookie值 - if( request()->post('online') == true ) - { - // 设置 - cookie('userid', session('userid')); - cookie('username', $data['username']); - cookie('password', $data['password']); - } - - // 将本次信息上传到服务器上 - $userinfo = tch::where('phone',$data['username']) - ->field('lastip,phone,ip,denglucishu,lasttime,thistime') - ->find(); - $userinfo->lastip = $userinfo->ip; - $userinfo->ip = request()->ip(); - $userinfo->denglucishu = ['inc', 1]; - $userinfo->lasttime = $userinfo->getData('thistime'); - $userinfo->thistime = time(); - $userinfo->save(); - - // 跳转到首页 - $data=['msg'=>'验证成功','status'=>1]; - }else{ - // 提示错误信息 - $data=['msg'=>$check['msg'],'status'=>0]; - } - - return json($data); - } - - - // 已知密码进行验证 - public function check($username,$password) - { - // 实例化加密类 - $md5 = new APR1_MD5(); - - // 获取服务器密码 - $userinfo = tch::where('phone', $username)->where('status', 1)->find(); - - if($userinfo == null) - { - // 清除session(当前作用域) - session(null); - // 验证结果; - $data=['msg'=>'手机号不存在或被禁用','status'=>0]; - return $data; - } - - //验证密码 - $check = $md5->check($password,$userinfo->password); - - if($check) - { - session('teacher', null); - session('onlineCategory', 'teacher'); - session('teacher.userid', $userinfo->id); - session('teacher.username', $username); - session('teacher.password', $password); - - $data=['msg'=>'验证成功','status'=>1]; - }else{ - // 清除cookie - cookie('userid', null); - cookie('username', null); - cookie('password', null); - // 清除session(当前作用域) - session(null); - $data=['msg'=>'手机号或密码错误','status'=>0]; - } - return $data; - } -} diff --git a/app/login/route/login.php b/app/login/route/login.php index 65d973eb..94d91621 100644 --- a/app/login/route/login.php +++ b/app/login/route/login.php @@ -14,7 +14,7 @@ use think\facade\Route; // 系统设置systembase Route::group('', function () { Route::rule('','Index/index','get'); - Route::rule('','Index/yanzheng','post'); + Route::rule('','Index/yanchengdenglu','post'); Route::rule('log','Index/shangmaLog','get'); # 配置更新 Route::rule('err','Index/myerror','get'); //错误页 Route::rule('weihu','Index/weihu','get'); //错误页 diff --git a/app/login/view/index/index.html b/app/login/view/index/index.html index 8804586d..7d723a66 100644 --- a/app/login/view/index/index.html +++ b/app/login/view/index/index.html @@ -42,7 +42,7 @@
- 增加数据库备份
+ 增加数据库备份
+ 合并用户登录