Skip to content

Commit

Permalink
Admin permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
hackjie committed Jul 19, 2018
1 parent 8fa473c commit 84b4bfc
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 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
27 changes: 27 additions & 0 deletions resources/views/pages/permission_denied.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
@extends('layouts.app')
@section('title', '无权限访问')

@section('content')

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

<a class="btn btn-lg btn-primary btn-block" href="{{ route('login') }}">
<span class="glyphicon glyphicon-log-in" aria-hidden="true"></span>
登 录
</a>
@endif
</div>
</div>
</div>

@stop
5 changes: 4 additions & 1 deletion routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,7 @@

Route::resource('replies', 'RepliesController', ['only' => ['store', 'destroy']]);

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

// 无权限访问
Route::get('permission-denied', 'PagesController@permissionDenied')->name('permission-denied');

0 comments on commit 84b4bfc

Please sign in to comment.