1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Modules\Admins; |
4
|
|
|
|
5
|
|
|
use App\Modules\Admins\Auth\AdminGuard; |
|
|
|
|
6
|
|
|
use App\Modules\Admins\Auth\AdminUserProvider; |
|
|
|
|
7
|
|
|
use App\Modules\Admins\Models\Admin; |
8
|
|
|
use App\Modules\Admins\Notifications\Auth\ResetPassword; |
9
|
|
|
use Illuminate\Support\Facades\Auth; |
10
|
|
|
use Illuminate\Support\Facades\Blade; |
11
|
|
|
use Illuminate\Support\ServiceProvider; |
12
|
|
|
|
13
|
|
|
class AdminServiceProvider extends ServiceProvider |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* Bootstrap the application services. |
17
|
|
|
*/ |
18
|
|
|
public function boot(): void |
19
|
|
|
{ |
20
|
|
|
$this->loadMigrationsFrom(__DIR__ . '/database/migrations'); |
21
|
|
|
$this->loadRoutesFrom(__DIR__ . '/routes/admin.php'); |
22
|
|
|
// $this->loadViewsFrom(__DIR__ . '/resources/views', 'admin'); |
23
|
|
|
|
24
|
|
|
// Blade::component('admin-app-layout', View\Components\AdminAppLayout::class); |
25
|
|
|
// Blade::component('admin-guest-layout', View\Components\AdminGuestLayout::class); |
26
|
|
|
|
27
|
|
|
// ResetPassword::createUrlUsing(function (object $notifiable, string $token) { |
28
|
|
|
// return config('app.frontend_url') . "/admin/password-reset/$token?email={$notifiable->getEmailForPasswordReset()}"; |
29
|
|
|
// }); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Register the application services. |
34
|
|
|
*/ |
35
|
|
|
public function register(): void |
36
|
|
|
{ |
37
|
|
|
$this->registerMiddleware(); |
38
|
|
|
$this->injectAuthConfiguration(); |
39
|
|
|
// $this->registerAuthDrivers('admins', 'admin', Admin::class); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @see https://laracasts.com/discuss/channels/general-discussion/register-middleware-via-service-provider |
44
|
|
|
*/ |
45
|
|
|
protected function registerMiddleware() |
46
|
|
|
{ |
47
|
|
|
$router = $this->app['router']; |
48
|
|
|
$router->aliasMiddleware('admin.auth', Http\Middleware\RedirectIfNotAdmin::class); |
49
|
|
|
$router->aliasMiddleware('admin.guest', Http\Middleware\RedirectIfAdmin::class); |
50
|
|
|
$router->aliasMiddleware('admin.verified', Http\Middleware\EnsureAdminEmailIsVerified::class); |
51
|
|
|
$router->aliasMiddleware('admin.password.confirm', Http\Middleware\RequireAdminPassword::class); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @see \Illuminate\Auth\AuthManager |
56
|
|
|
* @see https://www.devrohit.com/custom-authentication-in-laravel |
57
|
|
|
*/ |
58
|
|
|
protected function registerAuthDrivers(string $provider, string $guard, string $model) |
59
|
|
|
{ |
60
|
|
|
Auth::provider('admin_provider_driver', function ($app) use ($model) { |
61
|
|
|
return new AdminUserProvider($app['hash'], $model); |
62
|
|
|
}); |
63
|
|
|
|
64
|
|
|
/* AuthManager->createSessionDriver() */ |
65
|
|
|
Auth::extend('admin_guard_driver', function ($app) use ($provider, $guard) { |
66
|
|
|
$userProvider = Auth::createUserProvider($provider); |
67
|
|
|
|
68
|
|
|
$adminGuard = new AdminGuard($guard, $userProvider, $app['session.store']); |
69
|
|
|
|
70
|
|
|
if (method_exists($adminGuard, 'setCookieJar')) { |
71
|
|
|
$adminGuard->setCookieJar($this->app['cookie']); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
if (method_exists($adminGuard, 'setDispatcher')) { |
75
|
|
|
$adminGuard->setDispatcher($this->app['events']); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
if (method_exists($adminGuard, 'setRequest')) { |
79
|
|
|
$adminGuard->setRequest($this->app->refresh('request', $adminGuard, 'setRequest')); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
if (isset($config['remember'])) { |
|
|
|
|
83
|
|
|
$adminGuard->setRememberDuration($config['remember']); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
return $adminGuard; |
87
|
|
|
}); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
protected function injectAuthConfiguration() |
91
|
|
|
{ |
92
|
|
|
$this->app['config']->set('auth.guards.admin', [ |
93
|
|
|
'driver' => 'session', |
94
|
|
|
// 'driver' => 'admin_guard_driver', |
95
|
|
|
'provider' => 'admins', |
96
|
|
|
]); |
97
|
|
|
|
98
|
|
|
$this->app['config']->set('auth.providers.admins', [ |
99
|
|
|
'driver' => 'eloquent', |
100
|
|
|
// 'driver' => 'admin_provider_driver', |
101
|
|
|
'model' => Models\Admin::class, |
102
|
|
|
]); |
103
|
|
|
|
104
|
|
|
$this->app['config']->set('auth.passwords.admins', [ |
105
|
|
|
'provider' => 'admins', |
106
|
|
|
'table' => 'admin_password_reset_tokens', |
107
|
|
|
'expire' => 60, |
108
|
|
|
'throttle' => 60, |
109
|
|
|
]); |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths