From 246c95d956c1b055b02df64177a36947ee9a3a3a Mon Sep 17 00:00:00 2001 From: tensent Date: Mon, 27 Apr 2020 08:10:23 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=86=E7=A6=BB=E5=90=8E=E5=8F=B0=E5=92=8C?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E4=B8=AD=E5=BF=83=E7=99=BB=E5=BD=95=E7=8A=B6?= =?UTF-8?q?=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common.php | 23 ++++++++++++++++++----- app/controller/admin/Base.php | 1 + app/controller/admin/Index.php | 4 ++-- app/controller/user/Base.php | 9 +++++---- app/controller/user/Index.php | 18 +++++++++--------- view/admin/public/base.html | 6 +++--- 6 files changed, 38 insertions(+), 23 deletions(-) diff --git a/app/common.php b/app/common.php index 6ac27c60..a4b5b6d2 100755 --- a/app/common.php +++ b/app/common.php @@ -13,16 +13,29 @@ use think\facade\Session; use think\facade\Config; /** - * + * @title 检查登录状态 */ function is_login() { - $user = Session::get('userInfo'); - return isset($user['uid']) ? $user['uid'] : false; + if(strpos(Request::controller(), ".")){ + list($module, $controller) = explode(".", Request::controller()); + }else{ + $module = ""; + } + $user = Session::get(strtolower($module) . 'Info'); + return $user['uid']; } +/** + * @title 检查是否为超级管理员 + */ function is_administrator() { - $user = Session::get('userInfo'); - return (isset($user['uid']) && (int) $user['uid'] === (int) env('rootuid')) ? true : false; + if(strpos(Request::controller(), ".")){ + list($module, $controller) = explode(".", Request::controller()); + }else{ + $module = ""; + } + $user = Session::get(strtolower($module) . 'Info'); + return (int) $user['uid'] === (int) env('rootuid') ? true : false; } function form($field = [], $data = []) { diff --git a/app/controller/admin/Base.php b/app/controller/admin/Base.php index f5fd2801..f78f4343 100644 --- a/app/controller/admin/Base.php +++ b/app/controller/admin/Base.php @@ -14,6 +14,7 @@ use app\model\AuthGroup; use app\model\Menu; use app\model\Model; use think\facade\View; +use think\facade\Config; class Base extends BaseC { diff --git a/app/controller/admin/Index.php b/app/controller/admin/Index.php index 32bbf77f..39c8f874 100755 --- a/app/controller/admin/Index.php +++ b/app/controller/admin/Index.php @@ -48,7 +48,7 @@ class Index extends Base { try { $userinfo = $user->login($this->request); if ($userinfo) { - Session::set('userInfo', $userinfo); + Session::set('adminInfo', $userinfo); return $this->success('登录成功!', url('/admin/index/index')); } } catch (Exception $e) { @@ -64,7 +64,7 @@ class Index extends Base { * @return html */ public function logout(Member $user) { - Session::delete('userInfo'); + Session::delete('adminInfo'); $this->redirect('/admin/login'); } diff --git a/app/controller/user/Base.php b/app/controller/user/Base.php index 2bec6f7b..b91eda34 100644 --- a/app/controller/user/Base.php +++ b/app/controller/user/Base.php @@ -8,11 +8,12 @@ // +---------------------------------------------------------------------- namespace app\controller\user; -use think\facade\View; -use think\facade\Cache; use app\controller\Base as BaseC; -use app\model\Model; use app\model\Form; +use app\model\Model; +use think\facade\Cache; +use think\facade\Config; +use think\facade\View; class Base extends BaseC { @@ -46,7 +47,7 @@ class Base extends BaseC { $this->tpl_config['view_dir_name'] = 'public' . DIRECTORY_SEPARATOR . 'template' . DIRECTORY_SEPARATOR . $pc_themes; } } - if(!file_exists($this->app->getRootPath() . $this->tpl_config['view_dir_name'] . DIRECTORY_SEPARATOR . 'user')){ + if (!file_exists($this->app->getRootPath() . $this->tpl_config['view_dir_name'] . DIRECTORY_SEPARATOR . 'user')) { $this->tpl_config['view_dir_name'] = 'public' . DIRECTORY_SEPARATOR . 'template' . DIRECTORY_SEPARATOR . 'default'; } if ($template == '') { diff --git a/app/controller/user/Index.php b/app/controller/user/Index.php index e361dc81..0d8126ee 100644 --- a/app/controller/user/Index.php +++ b/app/controller/user/Index.php @@ -39,7 +39,7 @@ class Index extends Base { } catch (Exception $e) { return $this->error($e->getError(), ''); } - }else{ + } else { return $this->fetch(); } } @@ -62,10 +62,10 @@ class Index extends Base { $result = (new Member())->register($this->request); if (false !== $result) { return $this->success("注册成功!", url('/user/index/login')); - }else{ + } else { return $this->error("注册失败!"); } - }else{ + } else { return $this->fetch(); } } @@ -90,13 +90,13 @@ class Index extends Base { $result = Member::sendFindPaswd($user); if (false !== $result) { return $this->success("已发送找回密码邮件!", url('/user/index/login')); - }else{ + } else { return $this->error("发送邮件失败!"); } - }else{ + } else { return $this->error('无此用户!'); } - }else{ + } else { return $this->fetch(); } } @@ -124,13 +124,13 @@ class Index extends Base { $result = Member::update($data, ['uid' => $user['uid']]); if (false !== $result) { return $this->success("已重置!", url('/user/index/login')); - }else{ + } else { return $this->error("发送邮件失败!"); } - }else{ + } else { return $this->error('无此用户!'); } - }else{ + } else { $token = $this->request->param('token'); return $this->fetch(); } diff --git a/view/admin/public/base.html b/view/admin/public/base.html index 72c855a4..11023874 100644 --- a/view/admin/public/base.html +++ b/view/admin/public/base.html @@ -33,7 +33,7 @@