From aedb319156cd57aea5ecc636bc4ee6f43a495066 Mon Sep 17 00:00:00 2001 From: Summer Date: Fri, 20 Sep 2019 02:27:11 +0000 Subject: [PATCH] =?UTF-8?q?=E7=AB=99=E7=82=B9=E6=9D=83=E9=99=90=E9=83=A8?= =?UTF-8?q?=E7=BD=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Policies/Policy.php | 14 ++---- app/Providers/AppServiceProvider.php | 4 +- app/Providers/AuthServiceProvider.php | 5 ++ composer.json | 3 +- composer.lock | 48 ++++++++++++++++++- config/sudosu.php | 10 ++++ public/sudo-su/css/app.css | 68 +++++++++++++++++++++++++++ resources/views/layouts/app.blade.php | 4 ++ 8 files changed, 144 insertions(+), 12 deletions(-) create mode 100644 config/sudosu.php create mode 100644 public/sudo-su/css/app.css diff --git a/app/Policies/Policy.php b/app/Policies/Policy.php index 98a4a9c8b..2d8d4f18c 100644 --- a/app/Policies/Policy.php +++ b/app/Policies/Policy.php @@ -8,15 +8,11 @@ class Policy { use HandlesAuthorization; - public function __construct() + public function before($user, $ability) { - // + // 如果用户拥有管理内容的权限的话,即授权通过 + if ($user->can('manage_contents')) { + return true; + } } - - public function before($user, $ability) - { - // if ($user->isSuperAdmin()) { - // return true; - // } - } } diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index a7e2da1c1..e70be287a 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -13,7 +13,9 @@ class AppServiceProvider extends ServiceProvider */ public function register() { - // + if (app()->isLocal()) { + $this->app->register(\VIACreative\SudoSu\ServiceProvider::class); + } } /** diff --git a/app/Providers/AuthServiceProvider.php b/app/Providers/AuthServiceProvider.php index eed597b76..e5bbd9a3e 100644 --- a/app/Providers/AuthServiceProvider.php +++ b/app/Providers/AuthServiceProvider.php @@ -32,5 +32,10 @@ public function boot() // 动态返回模型对应的策略名称,如:// 'App\Model\User' => 'App\Policies\UserPolicy', return 'App\Policies\\'.class_basename($modelClass).'Policy'; }); + + \Horizon::auth(function ($request) { + // 是否是站长 + return \Auth::user()->hasRole('Founder'); + }); } } diff --git a/composer.json b/composer.json index 08c175cbf..7eed2aa74 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,8 @@ "overtrue/pinyin": "~4.0", "predis/predis": "~1.1", "spatie/laravel-permission": "~3.0", - "summerblue/laravel-active": "6.*" + "summerblue/laravel-active": "6.*", + "viacreative/sudo-su": "~1.1" }, "require-dev": { "barryvdh/laravel-debugbar": "~3.2", diff --git a/composer.lock b/composer.lock index dc27dbcf8..b2317ad81 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "c372bab41c772d7a86c20b2dc5768cae", + "content-hash": "e75b0b505b836a8c565a9ed2057c5e89", "packages": [ { "name": "cakephp/chronos", @@ -4196,6 +4196,52 @@ "homepage": "https://github.com/tijsverkoyen/CssToInlineStyles", "time": "2017-11-27T11:13:29+00:00" }, + { + "name": "viacreative/sudo-su", + "version": "1.1.0", + "source": { + "type": "git", + "url": "https://github.com/viacreative/sudo-su.git", + "reference": "78905d0db3721a5daece6f7fcd6c6567fd00bb46" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/viacreative/sudo-su/zipball/78905d0db3721a5daece6f7fcd6c6567fd00bb46", + "reference": "78905d0db3721a5daece6f7fcd6c6567fd00bb46", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "php": ">=7.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "VIACreative\\SudoSu\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Terry Harvey", + "email": "contact@terryharvey.co.uk" + } + ], + "description": "A utility package for logging in as other users", + "keywords": [ + "debugging", + "laravel" + ], + "time": "2017-03-23T16:28:08+00:00" + }, { "name": "vlucas/phpdotenv", "version": "v3.6.0", diff --git a/config/sudosu.php b/config/sudosu.php new file mode 100644 index 000000000..1b29d468e --- /dev/null +++ b/config/sudosu.php @@ -0,0 +1,10 @@ + ['dev', 'local', 'test'], + + // 用户模型 + 'user_model' => App\Models\User::class +]; diff --git a/public/sudo-su/css/app.css b/public/sudo-su/css/app.css new file mode 100644 index 000000000..ae4c544ef --- /dev/null +++ b/public/sudo-su/css/app.css @@ -0,0 +1,68 @@ +.sudoSu { + position: fixed; + right: 30px; + bottom: 30px; + z-index: 99999; +} + +.sudoSu__btn { + font-size: 1.5em; + background: #333; + width: 40px; + height: 40px; + line-height: 40px; + color: white; + text-align: center; + border-radius: 50%; +} + +.sudoSu__btn--hasSudoed { + background: #00b067; +} + +.sudoSu__interface { + position: absolute; + right: 60px; + bottom: 8px; +} + +.sudoSu__interface--hasSudoed { + background: white; + padding: 20px; + bottom: 0; + border: 1px solid #cecece; + border-radius: 5px; + box-shadow: 0 1px 1px rgba(0, 0, 0, 0.1); + width: 400px; +} + +.sudoSu__infoLine { + margin-bottom: 5px; +} + +.sudoSu__infoLine > span { + font-weight: bold; +} + +.sudoSu__resetBtn { + -webkit-appearance: none; + -moz-appearance: none; + cursor: pointer; + border: 0; + margin: 5px 0 15px 0; + padding: 6px 10px; + background: #00b067; + color: white; + border-radius: 4px; + border-bottom: 2px solid #088b54; +} + +.sudoSu__resetBtn:hover { + background: #088b54; +} + +.hidden { + display: none; +} + +/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInJlc291cmNlcy9hc3NldHMvc2Fzcy9hcHAuc2NzcyJdLCJzb3VyY2VzQ29udGVudCI6WyIuc3Vkb1N1IHtcbiAgICBwb3NpdGlvbjogZml4ZWQ7XG4gICAgcmlnaHQ6IDMwcHg7XG4gICAgYm90dG9tOiAzMHB4O1xuICAgIHotaW5kZXg6IDk5OTk5O1xuXG4gICAgJl9fYnRuIHtcbiAgICAgICAgZm9udC1zaXplOiAxLjVlbTtcbiAgICAgICAgYmFja2dyb3VuZDogIzMzMztcbiAgICAgICAgd2lkdGg6IDQwcHg7XG4gICAgICAgIGhlaWdodDogNDBweDtcbiAgICAgICAgbGluZS1oZWlnaHQ6IDQwcHg7XG4gICAgICAgIGNvbG9yOiB3aGl0ZTtcbiAgICAgICAgdGV4dC1hbGlnbjogY2VudGVyO1xuICAgICAgICBib3JkZXItcmFkaXVzOiA1MCU7XG5cbiAgICAgICAgJi0taGFzU3Vkb2VkIHtcbiAgICAgICAgICAgIGJhY2tncm91bmQ6ICMwMGIwNjc7XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICAmX19pbnRlcmZhY2Uge1xuICAgICAgICBwb3NpdGlvbjogYWJzb2x1dGU7XG4gICAgICAgIHJpZ2h0OiA2MHB4O1xuICAgICAgICBib3R0b206IDhweDtcblxuICAgICAgICAmLS1oYXNTdWRvZWQge1xuICAgICAgICAgICAgYmFja2dyb3VuZDogd2hpdGU7XG4gICAgICAgICAgICBwYWRkaW5nOiAyMHB4O1xuICAgICAgICAgICAgYm90dG9tOiAwO1xuICAgICAgICAgICAgYm9yZGVyOiAxcHggc29saWQgI2NlY2VjZTtcbiAgICAgICAgICAgIGJvcmRlci1yYWRpdXM6IDVweDtcbiAgICAgICAgICAgIGJveC1zaGFkb3c6IDAgMXB4IDFweCByZ2JhKDAsIDAsIDAsIDAuMSk7XG4gICAgICAgICAgICB3aWR0aDogNDAwcHg7XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICAmX19pbmZvTGluZSB7XG4gICAgICAgIG1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BQ0osT0FBTyxFQUFFLElBQUk7Q0FDaEIifQ== */ \ No newline at end of file diff --git a/resources/views/layouts/app.blade.php b/resources/views/layouts/app.blade.php index c0fad6dbd..57a3a8945 100644 --- a/resources/views/layouts/app.blade.php +++ b/resources/views/layouts/app.blade.php @@ -35,6 +35,10 @@ @include('layouts._footer') + @if (app()->isLocal()) + @include('sudosu::user-selector') + @endif +