From f29d425c1c549273a66547b7a9b2c29d4576c1be Mon Sep 17 00:00:00 2001 From: Summer Date: Fri, 20 Sep 2019 04:12:00 +0000 Subject: [PATCH] =?UTF-8?q?=E7=AE=A1=E7=90=86=E5=90=8E=E5=8F=B0=E6=9D=83?= =?UTF-8?q?=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/PagesController.php | 10 ++++++++ config/administrator.php | 4 +-- .../views/pages/permission_denied.blade.php | 25 +++++++++++++++++++ routes/web.php | 2 ++ 4 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 resources/views/pages/permission_denied.blade.php diff --git a/app/Http/Controllers/PagesController.php b/app/Http/Controllers/PagesController.php index b45cbb5c1..fd4eae271 100644 --- a/app/Http/Controllers/PagesController.php +++ b/app/Http/Controllers/PagesController.php @@ -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'); + } } diff --git a/config/administrator.php b/config/administrator.php index 6ae812fbf..1fe4e39a1 100644 --- a/config/administrator.php +++ b/config/administrator.php @@ -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', diff --git a/resources/views/pages/permission_denied.blade.php b/resources/views/pages/permission_denied.blade.php new file mode 100644 index 000000000..1053ce381 --- /dev/null +++ b/resources/views/pages/permission_denied.blade.php @@ -0,0 +1,25 @@ +@extends('layouts.app') +@section('title', '无权限访问') + +@section('content') +
+
+
+ @if (Auth::check()) +
+ 当前登录账号无后台访问权限。 +
+ @else +
+ 请登录以后再操作 +
+ + + + 登 录 + + @endif +
+
+
+@stop diff --git a/routes/web.php b/routes/web.php index 36a138351..b676a328c 100644 --- a/routes/web.php +++ b/routes/web.php @@ -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');