Skip to content

Commit

Permalink
管理后台权限
Browse files Browse the repository at this point in the history
  • Loading branch information
summerblue committed Sep 20, 2019
1 parent 6de91a3 commit f29d425
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 2 deletions.
10 changes: 10 additions & 0 deletions app/Http/Controllers/PagesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,14 @@ public function root()
{
return view('pages.root');
}

public function permissionDenied()
{
// 如果当前用户有权限访问后台,直接跳转访问
if (config('administrator.permission')()) {
return redirect(url(config('administrator.uri')), 302);
}
// 否则使用视图
return view('pages.permission_denied');
}
}
4 changes: 2 additions & 2 deletions config/administrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@
'dashboard_view' => '',

// 用来作为后台主页的菜单条目,由 `use_dashboard` 选项决定,菜单指的是 `menu` 选项
'home_page' => 'users',
'home_page' => 'topics',

// 右上角『返回主站』按钮的链接
'back_to_site_path' => '/',

// 当选项 `permission` 权限检测不通过时,会重定向用户到此处设置的路径
'login_path' => 'login',
'login_path' => 'permission-denied',

// 允许在登录成功后使用 Session::get('redirect') 将用户重定向到原本想要访问的后台页面
'login_redirect_key' => 'redirect',
Expand Down
25 changes: 25 additions & 0 deletions resources/views/pages/permission_denied.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
@extends('layouts.app')
@section('title', '无权限访问')

@section('content')
<div class="col-md-4 offset-md-4">
<div class="card ">
<div class="card-body">
@if (Auth::check())
<div class="alert alert-danger text-center mb-0">
当前登录账号无后台访问权限。
</div>
@else
<div class="alert alert-danger text-center">
请登录以后再操作
</div>

<a class="btn btn-lg btn-primary btn-block" href="{{ route('login') }}">
<i class="fas fa-sign-in-alt"></i>
登 录
</a>
@endif
</div>
</div>
</div>
@stop
2 changes: 2 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,5 @@
Route::resource('replies', 'RepliesController', ['only' => ['store', 'destroy']]);

Route::resource('notifications', 'NotificationsController', ['only' => ['index']]);

Route::get('permission-denied', 'PagesController@permissionDenied')->name('permission-denied');

0 comments on commit f29d425

Please sign in to comment.