├── .gitignore ├── LICENSE ├── README.md ├── composer.json ├── resources └── views │ └── lock.blade.php ├── routes └── web.php └── src ├── Http ├── Controllers │ └── LockScreenController.php └── Middleware │ └── LockScreen.php ├── LockScreen.php └── LockScreenServiceProvider.php /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | phpunit.phar 3 | /vendor 4 | composer.phar 5 | composer.lock 6 | *.project 7 | .idea/ -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Jens Segers 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Lock screen 2 | ====== 3 | 4 | Add a lock screen page to laravel-admin. 5 | 6 | [中文介绍](https://laravel-admin.org/posts/24) 7 | 8 | ## Screenshots 9 | 10 | ![wx20181114-232541](https://user-images.githubusercontent.com/1479100/48492459-c720f680-e864-11e8-934a-932d287479c4.png) 11 | 12 | ## Installation & Configuration 13 | 14 | ```bash 15 | composer require laravel-admin-ext/lock-screen 16 | ``` 17 | 18 | Then add a middleware `admin.lock` to routes configuration in `config/admin.php` 19 | 20 | ```php 21 | 22 | 'route' => [ 23 | 24 | 'prefix' => 'demo', 25 | 26 | 'namespace' => 'App\\Admin\\Controllers', 27 | 28 | // add middleware `admin.lock` into this array. 29 | 'middleware' => ['web', 'admin', 'admin.lock'], 30 | ], 31 | 32 | ``` 33 | 34 | ## Usage 35 | 36 | After installation and configuration, open the admin page, you will find a link in the upper right corner of the page with a lock icon, click it to redirect to the lock screen page, 37 | You need to enter your login password to return to unlock the page. 38 | 39 | ## Donate 40 | 41 | 如果觉得这个项目帮你节约了时间,不妨支持一下;) 42 | 43 | ![-1](https://cloud.githubusercontent.com/assets/1479100/23287423/45c68202-fa78-11e6-8125-3e365101a313.jpg) 44 | 45 | License 46 | ------------ 47 | Licensed under [The MIT License (MIT)](LICENSE). 48 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "laravel-admin-ext/lock-screen", 3 | "description": "Lock-screen page for laravel-admin", 4 | "type": "library", 5 | "keywords": ["laravel-admin", "extension", "lock screen"], 6 | "homepage": "https://github.com/laravel-admin-ext/lock-screen", 7 | "license": "MIT", 8 | "authors": [ 9 | { 10 | "name": "z-song", 11 | "email": "zosong@126.com" 12 | } 13 | ], 14 | "require": { 15 | "php": ">=7.0.0", 16 | "encore/laravel-admin": "~1.6" 17 | }, 18 | "require-dev": { 19 | "phpunit/phpunit": "~6.0" 20 | }, 21 | "autoload": { 22 | "psr-4": { 23 | "Encore\\Admin\\LockScreen\\": "src/" 24 | } 25 | }, 26 | "extra": { 27 | "laravel": { 28 | "providers": [ 29 | "Encore\\Admin\\LockScreen\\LockScreenServiceProvider" 30 | ] 31 | 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /resources/views/lock.blade.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | {{config('admin.title')}} | Lockscreen 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 19 | 20 | 21 | 22 | 23 |
24 | 27 | 28 |
{{ Admin::user()->name }}
29 | 30 | 31 |
32 | 33 |
34 | User Image 35 |
36 | 37 | 38 |
39 |
40 | 41 | 42 | 43 | {{ csrf_field() }} 44 | 45 |
46 | 47 |
48 |
49 |
50 | 51 |
52 | 53 |
54 | {{ trans('admin.logout') }} 55 |
56 |
57 | 58 | 59 | 60 | 61 | 62 | 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /routes/web.php: -------------------------------------------------------------------------------- 1 | name('laravel-admin-lock'); 6 | Route::post('auth/unlock', LockScreenController::class.'@unlock')->name('laravel-admin-unlock'); -------------------------------------------------------------------------------- /src/Http/Controllers/LockScreenController.php: -------------------------------------------------------------------------------- 1 | get(LockScreen::LOCK_KEY)) { 20 | $url = url()->previous(); 21 | session()->put(LockScreen::LOCK_KEY, $url); 22 | } 23 | 24 | return view('laravel-admin-lock-screen::lock'); 25 | } 26 | 27 | public function unlock(Request $request) 28 | { 29 | if (!Admin::user()) { 30 | return redirect(config('admin.route.prefix')); 31 | } 32 | 33 | if (!session()->has(LockScreen::LOCK_KEY)) { 34 | return redirect(admin_url()); 35 | } 36 | 37 | if (Hash::check(trim($request->get('password')), Admin::user()->password)) { 38 | $previous = session()->get(LockScreen::LOCK_KEY); 39 | 40 | session()->forget(LockScreen::LOCK_KEY); 41 | 42 | return redirect($previous); 43 | } 44 | 45 | return back()->withInput()->withException(new \Exception('password incorrect')); 46 | } 47 | } -------------------------------------------------------------------------------- /src/Http/Middleware/LockScreen.php: -------------------------------------------------------------------------------- 1 | shouldPassThrough($request)) { 20 | return $next($request); 21 | } 22 | 23 | if ($request->session()->has(Extension::LOCK_KEY)) { 24 | return redirect()->route('laravel-admin-lock'); 25 | } 26 | 27 | return $next($request); 28 | } 29 | 30 | protected function shouldPassThrough(Request $request) 31 | { 32 | foreach ($this->except as $except) { 33 | $except = trim(admin_base_path($except), '/'); 34 | 35 | if ($request->is($except)) { 36 | return true; 37 | } 38 | } 39 | 40 | return false; 41 | } 42 | } -------------------------------------------------------------------------------- /src/LockScreen.php: -------------------------------------------------------------------------------- 1 | 21 | 22 | 23 | 24 | 25 | HTML; 26 | 27 | } 28 | } -------------------------------------------------------------------------------- /src/LockScreenServiceProvider.php: -------------------------------------------------------------------------------- 1 | views()) { 23 | $this->loadViewsFrom($views, 'laravel-admin-lock-screen'); 24 | } 25 | 26 | $this->app->booted(function () { 27 | LockScreen::routes(__DIR__.'/../routes/web.php'); 28 | }); 29 | 30 | Admin::booting(function () { 31 | Admin::navbar(function (Navbar $navbar) { 32 | $navbar->right(LockScreen::link()); 33 | }); 34 | }); 35 | 36 | app('router')->aliasMiddleware('admin.lock', Middleware::class); 37 | } 38 | } --------------------------------------------------------------------------------