admin app bind

This commit is contained in:
toogee 2020-04-25 16:48:59 +08:00
parent 5873cebcfd
commit d126d0fc38
13 changed files with 64 additions and 53 deletions

View File

@ -198,9 +198,13 @@ class Admin extends AdminController
//清除缓存Cache //清除缓存Cache
public function clearCache(){ public function clearCache(){
$atemp = app()->getRootPath().'runtime/admin/temp/'; //$atemp = app()->getRootPath().'runtime/admin/temp/';
$itemp = app()->getRootPath().'runtime/index/temp/'; //$itemp = app()->getRootPath().'runtime/index/temp/';
$cache = app()->getRootPath().'runtime/cache/'; //$cache = app()->getRootPath().'runtime/cache/';
$atemp = str_replace('\\',"/",app()->getRootPath().'runtime/admin/temp/');
$itemp = str_replace('\\',"/",app()->getRootPath().'runtime/index/temp/');
$cache = str_replace('\\',"/",app()->getRootPath().'runtime/cache/');
Files::delDirAndFile($atemp); Files::delDirAndFile($atemp);
Files::delDirAndFile($itemp); Files::delDirAndFile($itemp);
if(is_dir($cache) && Files::delDirAndFile($cache)){ if(is_dir($cache) && Files::delDirAndFile($cache)){
@ -209,4 +213,13 @@ class Admin extends AdminController
return json(['code'=>-1,'msg'=>'清除缓存失败']); return json(['code'=>-1,'msg'=>'清除缓存失败']);
} }
} }
//退出登陆
public function logout()
{
Session::clear();
$res = ['code'=>0,'msg'=>'退出成功' ];
return json($res);
}
} }

View File

@ -157,16 +157,6 @@ class User extends AdminController
return json($res); return json($res);
} }
//退出登陆
public function logout()
{
Session::clear();
$res = ['code'=>0,'msg'=>'退出成功' ];
return json($res);
}
//过滤数组中为空和null的值 //过滤数组中为空和null的值
public function filtrArr($arr) public function filtrArr($arr)
{ {

View File

@ -17,36 +17,34 @@ class Auth
*/ */
public function handle($request, \Closure $next) public function handle($request, \Closure $next)
{ {
//halt($request->pathinfo());
$response = $next($request); $response = $next($request);
//后置中间件获取应用控制器方法
if($request->controller() !== 'Login' && $request->action() !=='logout')
{
//登陆检验
if (!Session::has('admin_id')) {
return redirect((string) url('admin/login/index'));
}
$app = app('http')->getName(); $app = app('http')->getName();
$controller = $request->controller(); $controller = $request->controller();
$action = $request->action(); $action = $request->action();
//登陆后检验权限
if (Session::has('admin_id')) {
// 排除权限 // 排除权限
$not_check = ['admin/Index/index','admin/Index/home','admin/Set/info','admin/Set/password','admin/User/logout']; $not_check = ['admin/Index/index','admin/Index/home','admin/Set/info','admin/Set/password','admin/User/logout'];
if (!in_array($app . '/' . $controller . '/' . $action, $not_check)) { if (!in_array($app . '/' . $controller . '/' . $action, $not_check)) {
$auth = new UserAuth(); $auth = new UserAuth();
$admin_id = Session::get('admin_id'); $admin_id = Session::get('admin_id'); //登录用户的id
if (!$auth->check($app . '/' . $controller . '/' . $action, $admin_id) && $admin_id != 1) { if (!$auth->check($app . '/' . $controller . '/' . $action, $admin_id) && $admin_id != 1) {
//return response('<script>alert("没有权限");location.back()</script>');
//return response('没有权限');
return json(['code'=>-1,'msg'=>'没有权限!']); return json(['code'=>-1,'msg'=>'没有权限!']);
} }
} }
}
} else {
//排除登录页和验证码被重定向
if($controller !== 'Login' && !stristr($request->pathinfo(),"captcha.html") && $action !== 'logout')
{
//非登录重定向
return redirect((string) url('admin/login/index'));
}
}
return $response; return $response;
} }
} }

View File

@ -458,7 +458,7 @@ layui.define('view', function(exports){
}); });
admin.req({ admin.req({
type: "post" type: "post"
,url: '/admin/Admin/clearCache' ,url: adminClearCache
,success: function(data){ ,success: function(data){
if (data.code == 0) { if (data.code == 0) {
layer.close(loading); layer.close(loading);

View File

@ -24,7 +24,7 @@ layui.define(function(exports){
admin.events.logout = function(){ admin.events.logout = function(){
//执行退出接口 //执行退出接口
admin.req({ admin.req({
url: '/admin/user/logout' url: AdminLogout
,type: 'get' ,type: 'get'
,data: {} ,data: {}
,done: function(res){ //这里要说明一下done 是只有 response 的 code 正常才会执行。而 succese 则是只要 http 为 200 就会执行 ,done: function(res){ //这里要说明一下done 是只有 response 的 code 正常才会执行。而 succese 则是只要 http 为 200 就会执行
@ -36,10 +36,8 @@ layui.define(function(exports){
icon:1, icon:1,
time:2000 time:2000
}, function(){ }, function(){
location.href = '/admin/login/index'; location.href = AdminLogin;
}); });
//location.href = '/admin/login/index';
}); });
} }
}); });

View File

@ -191,7 +191,7 @@ layui.define(function(exports){
//本周发贴 //本周发贴
table.render({ table.render({
elem: '#LAY-index-topSearch' elem: '#LAY-index-topSearch'
,url: '/admin/index/forums' //模拟接口 ,url: indexForums //发贴接口
,page: true ,page: true
,cellMinWidth: 120 ,cellMinWidth: 120
,cols: [[ ,cols: [[
@ -207,7 +207,7 @@ layui.define(function(exports){
//本周评论 //本周评论
table.render({ table.render({
elem: '#LAY-index-topCard' elem: '#LAY-index-topCard'
,url: '/admin/index/replys' //模拟接口 ,url: indexReplys //评论接口
,page: true ,page: true
,cellMinWidth: 120 ,cellMinWidth: 120
,cols: [[ ,cols: [[

View File

@ -79,7 +79,7 @@ layui.define(['table', 'form'], function(exports){
//分类管理 //分类管理
table.render({ table.render({
elem: '#LAY-app-content-tags' elem: '#LAY-app-content-tags'
,url: '/admin/Forum/tags' //模拟接口 ,url: '/Forum/tags' //模拟接口
,cols: [[ ,cols: [[
{type: 'numbers', fixed: 'left'} {type: 'numbers', fixed: 'left'}
,{field: 'sort', title: '排序', width: 80, sort: true} ,{field: 'sort', title: '排序', width: 80, sort: true}

View File

@ -57,7 +57,7 @@ layui.define('form', function(exports){
//更换图形验证码 //更换图形验证码
$body.on('click', '#LAY-user-get-vercode', function(){ $body.on('click', '#LAY-user-get-vercode', function(){
var othis = $(this); var othis = $(this);
this.src = '/captcha?t='+ new Date().getTime() this.src = '/captcha.html?t='+ new Date().getTime()
}); });
//对外暴露的接口 //对外暴露的接口

View File

@ -95,6 +95,9 @@
{block name="js"} {block name="js"}
<script> <script>
var forumList = "{:url('Forum/list')}",
forumListdel = "{:url('Forum/listdel')}",
forumListform = "{:url('Forum/listform')}";
layui.config({ layui.config({
base: '/static/admin/' //静态资源所在路径 base: '/static/admin/' //静态资源所在路径
}).extend({ }).extend({

View File

@ -14,49 +14,49 @@
<div carousel-item> <div carousel-item>
<ul class="layui-row layui-col-space10"> <ul class="layui-row layui-col-space10">
<li class="layui-col-xs3"> <li class="layui-col-xs3">
<a lay-href="{:url('admin/forum/list')}"> <a lay-href="{:url('Forum/list')}">
<i class="layui-icon layui-icon-list"></i> <i class="layui-icon layui-icon-list"></i>
<cite>帖子</cite> <cite>帖子</cite>
</a> </a>
</li> </li>
<li class="layui-col-xs3"> <li class="layui-col-xs3">
<a lay-href="{:url('admin/forum/replys')}"> <a lay-href="{:url('Forum/replys')}">
<i class="layui-icon layui-icon-survey"></i> <i class="layui-icon layui-icon-survey"></i>
<cite>评论</cite> <cite>评论</cite>
</a> </a>
</li> </li>
<li class="layui-col-xs3"> <li class="layui-col-xs3">
<a lay-href="{:url('admin/forum/tags')}"> <a lay-href="{:url('Forum/tags')}">
<i class="layui-icon layui-icon-template-1"></i> <i class="layui-icon layui-icon-template-1"></i>
<cite>分类</cite> <cite>分类</cite>
</a> </a>
</li> </li>
<li class="layui-col-xs3"> <li class="layui-col-xs3">
<a lay-href="{:url('admin/Admin/repass')}"> <a lay-href="{:url('Admin/repass')}">
<i class="layui-icon layui-icon-password"></i> <i class="layui-icon layui-icon-password"></i>
<cite>密码</cite> <cite>密码</cite>
</a> </a>
</li> </li>
<li class="layui-col-xs3"> <li class="layui-col-xs3">
<a lay-href="{:url('admin/slider/index')}"> <a lay-href="{:url('Slider/index')}">
<i class="layui-icon layui-icon-dollar"></i> <i class="layui-icon layui-icon-dollar"></i>
<cite>广告</cite> <cite>广告</cite>
</a> </a>
</li> </li>
<li class="layui-col-xs3"> <li class="layui-col-xs3">
<a lay-href="{:url('admin/Admin/info')}"> <a lay-href="{:url('Admin/info')}">
<i class="layui-icon layui-icon-form"></i> <i class="layui-icon layui-icon-form"></i>
<cite>资料</cite> <cite>资料</cite>
</a> </a>
</li> </li>
<li class="layui-col-xs3"> <li class="layui-col-xs3">
<a lay-href="{:url('admin/User/list')}"> <a lay-href="{:url('User/list')}">
<i class="layui-icon layui-icon-user"></i> <i class="layui-icon layui-icon-user"></i>
<cite>用户</cite> <cite>用户</cite>
</a> </a>
</li> </li>
<li class="layui-col-xs3"> <li class="layui-col-xs3">
<a lay-href="{:url('admin/set/website')}"> <a lay-href="{:url('Set/website')}">
<i class="layui-icon layui-icon-set"></i> <i class="layui-icon layui-icon-set"></i>
<cite>设置</cite> <cite>设置</cite>
</a> </a>
@ -287,5 +287,7 @@
}).extend({ }).extend({
index: 'lib/index' //主入口模块 index: 'lib/index' //主入口模块
}).use(['index', 'console']); }).use(['index', 'console']);
var indexForums = "{:url('Index/forums')}",
indexReplys = "{:url('Index/replys')}";
</script> </script>
{/block} {/block}

View File

@ -14,6 +14,13 @@
{block name="body"}内容{/block} {block name="body"}内容{/block}
<script src="/static/layui/jquery.min.js" charset="utf-8"></script> <script src="/static/layui/jquery.min.js" charset="utf-8"></script>
<script src="/static/layui/layui.js"></script> <script src="/static/layui/layui.js"></script>
<script type="text/javascript" charset="utf-8">
var AdminLogin = "{:url('Login/index')}",
AdminLogout = "{:url('Admin/logout')}",
adminClearCache = "{:url('Admin/clearCache')}";
//var c = "{:config('app.domain_bind.www')}";
//console.log(c);
</script>
{block name="js"}js文件{/block} {block name="js"}js文件{/block}
</body> </body>
</html> </html>

View File

@ -55,8 +55,8 @@
<cite>{:session('admin_name')}</cite> <cite>{:session('admin_name')}</cite>
</a> </a>
<dl class="layui-nav-child"> <dl class="layui-nav-child">
<dd><a lay-href="{:url('admin/admin/info')}">基本资料</a></dd> <dd><a lay-href="{:url('Admin/info')}">基本资料</a></dd>
<dd><a lay-href="{:url('admin/admin/repass')}">修改密码</a></dd> <dd><a lay-href="{:url('Admin/repass')}">修改密码</a></dd>
<hr> <hr>
<dd layadmin-event="logout" style="text-align: center;"><a>退出</a></dd> <dd layadmin-event="logout" style="text-align: center;"><a>退出</a></dd>
</dl> </dl>

View File

@ -25,7 +25,7 @@
</a> </a>
<dl class="layui-nav-child"> <dl class="layui-nav-child">
<dd> <dd>
<a lay-href="{:url('admin/user/list')}">网站用户</a> <a lay-href="{:url('User/list')}">网站用户1</a>
</dd> </dd>
<dd> <dd>
<a lay-href="{:url('admin/admin/adminList')}">后台管理员</a> <a lay-href="{:url('admin/admin/adminList')}">后台管理员</a>