Browse Source

权限判断

master
林一峰 8 years ago
parent
commit
5c02961178
  1. 33
      app/Common/function.php
  2. 22
      app/Http/Controllers/Admin/CommonController.php
  3. 2
      app/Http/Controllers/Admin/LoginController.php
  4. 18
      app/Http/Model/Menu.php
  5. 2
      public/css/admin.css
  6. 8
      resources/views/admin/index/index.blade.php
  7. 2
      resources/views/admin/menu/add.blade.php
  8. 2
      resources/views/admin/menu/edit.blade.php
  9. 2
      resources/views/admin/user/index.blade.php
  10. 2
      resources/views/admin/userrole/index.blade.php

33
app/Common/function.php

@ -622,8 +622,19 @@ function imgmatch($url)
function get_category($modelname, $parent_id=0, $pad=0)
{
$arr = array();
$temp = \DB::table($modelname)->where('pid', $parent_id);
if(get_table_columns($modelname, 'listorder'))
{
$temp = $temp->orderBy('listorder', 'asc');
}
else
{
$temp = $temp->orderBy('id', 'asc');
}
$temp = $temp->get();
$temp = \DB::table($modelname)->where('pid', $parent_id)->orderBy('id', 'asc')->get();
$cats = object_to_array($temp);
if($cats)
@ -1032,6 +1043,26 @@ function success_jump($msg='', $url='', $time=1)
}
}
//获取表所有字段
function get_table_columns($table, $field='')
{
$res = \Illuminate\Support\Facades\Schema::getColumnListing($table);
if($field != '')
{
//判断字段是否在表里面
if(in_array($field, $res))
{
return true;
}
else
{
return false;
}
}
return $res;
}

22
app/Http/Controllers/Admin/CommonController.php

@ -12,6 +12,7 @@ class CommonController extends Controller
{
parent::__construct();
//判断是否登录
if(isset($_SESSION['admin_user_info']))
{
$this->user_info = $_SESSION['admin_user_info'];
@ -20,6 +21,27 @@ class CommonController extends Controller
{
header("Location:".route('page404'));
exit();
}
//判断是否拥有权限
if($_SESSION['admin_user_info']['role_id'] <> 1)
{
$uncheck = array('admin_jump','admin','admin_index_upconfig','admin_index_upcache','admin_welcome');
if(in_array(\Route::currentRouteName(), $uncheck))
{
}
else
{
$menu_id = DB::table('menu')->where('action', \Route::currentRouteName())->value('id');
$check = DB::table('access')->where(['role_id' => $_SESSION['admin_user_info']['role_id'], 'menu_id' => $menu_id])->first();
if(!$check)
{
error_jump('你没有权限访问,请联系管理员!', route('admin'));
}
}
}
}

2
app/Http/Controllers/Admin/LoginController.php

@ -42,7 +42,7 @@ class LoginController extends BaseController
if($User)
{
$admin_user_info = $User->toArray();
$admin_user_info['rolename'] = $User->userrole->rolename;
$admin_user_info['rolename'] = $User->userrole->name;
$_SESSION['admin_user_info'] = $admin_user_info;

18
app/Http/Model/Menu.php

@ -9,24 +9,6 @@ class Menu extends Model
public $timestamps = false;
protected $guarded = []; //$guarded包含你不想被赋值的字段数组。
/**
* 文件上传
* @param $field
* @return string
*/
public function uploadImg($field)
{
if (Request::hasFile($field)) {
$pic = Request::file($field);
if ($pic->isValid()) {
$newName = md5(rand(1, 1000) . $pic->getClientOriginalName()) . "." . $pic->getClientOriginalExtension();
$pic->move('uploads', $newName);
return $newName;
}
}
return '';
}
//获取后台管理员所具有权限的菜单列表
public static function getPermissionsMenu($role_id, $pid=0, $pad=0)
{

2
public/css/admin.css

@ -1,7 +1,7 @@
.mauto{margin-left:auto;margin-right:auto;}
.blog-masthead{background-color:#01aef0;}
.blog-nav-item{position:relative;display:inline-block;padding:15px 20px;font-weight:500;color:#fff;font-size:16px;}
.blog-nav-item{position:relative;display:inline-block;padding:12px 20px;font-weight:500;color:#fff;font-size:16px;}
.blog-nav-item:hover,.blog-nav-item:focus{background-color:#00a9e9;color:#fff;text-decoration:none;}
.blog-nav .active{background-color:#00a9e9;color:#fff;}
.blog-nav .active:after{position:absolute;bottom:0;left:50%;width:0;height:0;margin-left:-5px;vertical-align:middle;content:" ";border-right:5px solid transparent;border-bottom:5px solid;border-left:5px solid transparent;}

8
resources/views/admin/index/index.blade.php

@ -2,7 +2,7 @@
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="<?php echo route('home'); ?>/css/bootstrap.min.css"><link rel="stylesheet" href="<?php echo route('home'); ?>/css/admin.css">
<script src="<?php echo route('home'); ?>/js/jquery.min.js"></script><script src="<?php echo route('home'); ?>/js/ad.js"></script><script src="<?php echo route('home'); ?>/js/bootstrap.min.js"></script><script type="text/javascript" src="<?php echo route('home'); ?>/js/jquery.uploadify.min.js"></script></head><body>
<script src="<?php echo route('home'); ?>/js/jquery.min.js"></script><script src="<?php echo route('home'); ?>/js/ad.js"></script><script src="<?php echo route('home'); ?>/js/bootstrap.min.js"></script></head><body>
<div class="blog-masthead clearfix"><nav class="blog-nav">
<a class="blog-nav-item active" href="<?php echo route('admin'); ?>"><span class="glyphicon glyphicon-star"></span> <strong>后台管理中心</strong> <span class="glyphicon glyphicon-star-empty"></span></a>
@ -44,14 +44,14 @@ $(document).ready(function(){
</script>
<div class="menu">
<ul class="leftmenu">
<?php if($menus){ foreach($menus as $k=>$first){ ?>
<?php if($menus){ foreach($menus as $k=>$first){if(!isset($first['child']) && $first['deep']==0){}else{ ?>
<!-- 一级菜单 -->
<li><a href="<?php if(isset($first['child'])){echo 'javascript:;';}else{echo route($first['action']);} ?>" class="<?php if(isset($first['child'])){echo 'inactive ';} if($k==0){echo 'active ';} ?>"><?php if($first['icon']){echo '<small class="'.$first['icon'].'"></small>';} ?> <?php echo $first['name']; ?></a>
<!-- 二级菜单 -->
<?php if(isset($first['child'])){ ?>
<ul style="display: none">
<?php foreach($first['child'] as $second){ ?>
<li><a target="appiframe" href="<?php if(isset($second['child'])){echo 'javascript:;';}else{echo route($second['action']);} ?>" class="<?php if(isset($second['child'])){echo 'inactive ';} ?>"><small class="glyphicon glyphicon-triangle-right"></small> <?php echo $second['name']; ?></a>
<li><a target="appiframe" href="<?php if(isset($second['child'])){echo 'javascript:;';}else{echo route($second['action']);} ?>" class="<?php if(isset($second['child'])){echo 'inactive ';} ?>"><small class="glyphicon glyphicon-hand-right"></small> <?php echo $second['name']; ?></a>
<!-- 三级菜单 -->
<?php if(isset($second['child'])){ ?>
<ul><?php foreach($second['child'] as $third){ ?>
@ -61,7 +61,7 @@ $(document).ready(function(){
<?php } ?>
</ul><?php } ?>
</li>
<?php }} ?>
<?php }}} ?>
</ul>
</div>
</div><!-- 左边结束 -->

2
resources/views/admin/menu/add.blade.php

@ -35,7 +35,7 @@
</tr>
<tr>
<td align="right">图标:</td>
<td><input name="icon" type="text" id="icon" value="" style="width:30%"></td>
<td><input name="icon" type="text" id="icon" value="" style="width:30%"> <small style="color:#999">(Glyphicons字体图标,如glyphicon glyphicon-home)</small></td>
</tr>
<tr>
<td align="right">备注:</td>

2
resources/views/admin/menu/edit.blade.php

@ -35,7 +35,7 @@
</tr>
<tr>
<td align="right">图标:</td>
<td><input name="icon" type="text" id="icon" value="<?php echo $post["icon"]; ?>" style="width:30%"></td>
<td><input name="icon" type="text" id="icon" value="<?php echo $post["icon"]; ?>" style="width:30%"> <small style="color:#999">(Glyphicons字体图标,如glyphicon glyphicon-home)</small></td>
</tr>
<tr>
<td align="right">备注:</td>

2
resources/views/admin/user/index.blade.php

@ -18,7 +18,7 @@
<td><?php echo $row->username; ?></td>
<td><?php echo $row->email; ?></td>
<td><?php if($row->status==0){echo '正常';}elseif($row->status==1){echo '禁用';}elseif($row->status==2){echo '禁用';} ?></td>
<td><a href="/fladmin/user/edit?id=<?php echo $row->id; ?>">权限设置</a> | <a href="/fladmin/user/edit?id=<?php echo $row->id; ?>">修改</a> | <a onclick="delconfirm('/fladmin/user/del?id=<?php echo $row->id; ?>')" href="javascript:;">删除</a></td>
<td><a href="/fladmin/user/edit?id=<?php echo $row->id; ?>">修改</a><?php if($row->id<>1){ ?> | <a onclick="delconfirm('/fladmin/user/del?id=<?php echo $row->id; ?>')" href="javascript:;">删除</a><?php } ?></td>
</tr><?php } ?>
</tbody></table></div><!-- 表格结束 --></form><!-- 表单结束 -->

2
resources/views/admin/userrole/index.blade.php

@ -18,7 +18,7 @@
<td><?php echo $row->name; ?></td>
<td><?php echo $row->des; ?></td>
<td><?php if($row->status==0){echo '启用';}else{echo '禁用';} ?></td>
<td><?php if($row->id<>1){ ?><a href="/fladmin/userrole/permissions?id=<?php echo $row->id; ?>">权限设置</a> | <?php } ?><a href="/fladmin/userrole/edit?id=<?php echo $row->id; ?>">修改</a> | <a onclick="delconfirm('/fladmin/userrole/del?id=<?php echo $row->id; ?>')" href="javascript:;">删除</a></td>
<td><?php if($row->id<>1){ ?><a href="/fladmin/userrole/permissions?id=<?php echo $row->id; ?>">权限设置</a> | <?php } ?><a href="/fladmin/userrole/edit?id=<?php echo $row->id; ?>">修改</a><?php if($row->id<>1){ ?> | <a onclick="delconfirm('/fladmin/userrole/del?id=<?php echo $row->id; ?>')" href="javascript:;">删除</a><?php } ?></td>
</tr><?php } ?>
</tbody></table></div><!-- 表格结束 --></form><!-- 表单结束 -->

Loading…
Cancel
Save