From 335d3c279b62369b47848d9b30613c8be2dafd6c Mon Sep 17 00:00:00 2001 From: Anyon Date: Mon, 13 Feb 2017 01:28:39 -0500 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E7=99=BB=E5=BD=95=E7=99=BB?= =?UTF-8?q?=E5=87=BA=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/controller/Login.php | 15 ++++++++++++--- extend/controller/BasicAdmin.php | 21 +++++++++++++++++++-- public/static/admin/plugs.js | 24 +++++++----------------- 3 files changed, 38 insertions(+), 22 deletions(-) diff --git a/application/admin/controller/Login.php b/application/admin/controller/Login.php index aec8a2177..8c8bfdf78 100644 --- a/application/admin/controller/Login.php +++ b/application/admin/controller/Login.php @@ -1,17 +1,26 @@ * @date 2017/02/10 13:59 */ -class Login extends Controller { +class Login extends BasicAdmin { + + /** + * 控制器基础方法 + */ + public function _initialize() { + if ($this->isLogin() && $this->request->action() !== 'out') { + $this->redirect('@admin'); + } + } /** * 用户登录 diff --git a/extend/controller/BasicAdmin.php b/extend/controller/BasicAdmin.php index 7559d1f2b..f08a4667e 100644 --- a/extend/controller/BasicAdmin.php +++ b/extend/controller/BasicAdmin.php @@ -4,16 +4,33 @@ namespace controller; use think\Controller; +/** + * 后台权限基础控制器 + * + * @package controller + * @author Anyon + * @date 2017/02/13 14:24 + */ class BasicAdmin extends Controller { + /** + * 后台权限控制初始化方法 + */ public function _initialize() { - parent::_initialize(); if (!$this->isLogin()) { $this->redirect('@admin/login'); } } + /** + * 判断用户是否登录 + * @return bool + */ public function isLogin() { - return false; + $user = session('user'); + if (empty($user) || empty($user['id'])) { + return false; + } + return true; } } \ No newline at end of file diff --git a/public/static/admin/plugs.js b/public/static/admin/plugs.js index 1f32161ea..2125affd0 100644 --- a/public/static/admin/plugs.js +++ b/public/static/admin/plugs.js @@ -161,25 +161,15 @@ define(['zeroclipboard', 'jquery', 'layui'], function (ZeroClipboard) { */ msg.prototype.auto = function (data, time) { var self = this; - if (data.code === 1) { - self.success(data.msg, time, function () { - if (data.url === 'back') { - window.history.back(); - } else if (data.url === 'reload') { - $.form.reload(); - } else if (data.url) { - window.location.href = data.url; - } else { - $.form.reload(); - } - }); - } else { - self.error(data.msg, 3000, function () { - if (data.url) { - window.location.href = data.url; - } + if (parseInt(data.code) === 1) { + return self.success(data.msg, time, function () { + alert(data.url); + !!data.url ? (window.location.href = data.url) : $.form.reload(); }); } + self.error(data.msg, 3000, function () { + !!data.url && (window.location.href = data.url); + }); }; /**