From 44e649084a4d495789e8e887e89bce84992f4a9f Mon Sep 17 00:00:00 2001 From: zhaoxiang <756958008@qq.com> Date: Sun, 6 Nov 2016 17:30:36 +0800 Subject: [PATCH] =?UTF-8?q?added=20=E4=BC=98=E5=8C=96jump=E8=B7=B3?= =?UTF-8?q?=E8=BD=AC=E9=A1=B5=E9=9D=A2=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/controller/Base.php | 52 +++++++++++++++++++- application/admin/controller/User.php | 8 ++-- application/admin/view/public/jump.html | 63 +++++++++++++++++++++++++ application/config.php | 4 +- 4 files changed, 120 insertions(+), 7 deletions(-) create mode 100644 application/admin/view/public/jump.html diff --git a/application/admin/controller/Base.php b/application/admin/controller/Base.php index a040d3f..31bfca9 100644 --- a/application/admin/controller/Base.php +++ b/application/admin/controller/Base.php @@ -6,12 +6,17 @@ */ namespace app\admin\controller; +use app\admin\model\User; use think\Controller; class Base extends Controller { public $primaryKey; public $uid; + public $userInfo; + private $superUrl = [ + 'User/login' + ]; public function _initialize(){ $this->primaryKey = config('SQL_PRIMARY_KEY'); @@ -19,7 +24,7 @@ class Base extends Controller { //初始化系统 $this->uid = session('uid'); $this->assign('uid',$this->uid); -// $this->iniSystem(); + $this->iniSystem(); //控制器初始化 if(method_exists($this,'_myInitialize')){ @@ -33,4 +38,49 @@ class Base extends Controller { public function _empty(){ return (new PublicShow())->show_404(); } + + /** + * 系统初始化函数(登陆状态检测,权限检测,初始化菜单) + */ + private function iniSystem(){ + $url = $this->request->controller().'/'.$this->request->action(); + if( !in_array($url, $this->superUrl) ){ +// $this->allMenu = D('Menu')->order('sort asc')->select(); +// $this->menuInfo = D('Menu')->where(['url' => $this->url])->find(); +// if( empty($this->menuInfo) ){ +// $this->error( 'Menu'.L('_SELECT_NOT_EXIST_') ); +// } + $this->checkLogin(); +// $this->checkRule(); + } + } + + /** + * 用户登录状态检测 + */ + private function checkLogin(){ + if( isset($this->uid) && !empty($this->uid) ){ + $sidNow = session_id(); + $sidOld = cache($this->uid); + if( isset($sidOld) && !empty($sidOld) ){ + if( $sidOld != $sidNow ){ + $this->error("您的账号在别的地方登录了,请重新登录!", url('User/login')); + }else{ + cache($this->uid, $sidNow, config('online_time')); + $this->userInfo = User::get([ $this->primaryKey => $this->uid ]); + if( $this->userInfo['updateTime'] === 0 ){ + $this->error('初次登录请重置用户密码!', url('User/changePassWord')); + }else{ + if( empty($this->userInfo['nickName']) ){ + $this->error('初次登录请设置用户昵称!', url('User/changeNickname')); + } + } + } + }else{ + $this->error("登录超时,请重新登录!", url('User/login')); + } + }else{ + $this->redirect('Login/index'); + } + } } \ No newline at end of file diff --git a/application/admin/controller/User.php b/application/admin/controller/User.php index 54ede15..cc96fee 100644 --- a/application/admin/controller/User.php +++ b/application/admin/controller/User.php @@ -21,13 +21,13 @@ class User extends Base { $username = $this->request->post('username'); $password = $this->request->post('password'); if( !$username || !$password ){ - return $this->error('缺少关键数据!'); + $this->error('缺少关键数据!',''); } $userModel = new \app\admin\model\User(); $password = $userModel->getPwdHash($password); $userInfo = $userModel->where(['username' => $username, 'password' => $password])->find(); if( empty($userInfo) ){ - return $this->error('用户名或者密码错误!'); + $this->error('用户名或者密码错误!',''); }else{ if( $userInfo['status'] ){ //保存用户信息和登录凭证 @@ -50,9 +50,9 @@ class User extends Base { $newUserData->uid = $userInfo[$this->primaryKey]; $newUserData->save(); } - return $this->success('登录成功', $url); + $this->success('登录成功', $url); }else{ - return $this->error('用户已被封禁,请联系管理员'); + $this->error('用户已被封禁,请联系管理员',''); } } }else{ diff --git a/application/admin/view/public/jump.html b/application/admin/view/public/jump.html new file mode 100644 index 0000000..ea84e62 --- /dev/null +++ b/application/admin/view/public/jump.html @@ -0,0 +1,63 @@ +{__NOLAYOUT__} + + +
+ +