X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/3b31ac75ec41b3990cea770a9e48e2066bd8e9a3..refs/pull/5721/head:/app/App/Providers/AuthServiceProvider.php diff --git a/app/App/Providers/AuthServiceProvider.php b/app/App/Providers/AuthServiceProvider.php index dc482ce33..23c339079 100644 --- a/app/App/Providers/AuthServiceProvider.php +++ b/app/App/Providers/AuthServiceProvider.php @@ -9,6 +9,7 @@ use BookStack\Access\LdapService; use BookStack\Access\LoginService; use BookStack\Access\RegistrationService; use BookStack\Api\ApiTokenGuard; +use BookStack\Users\Models\User; use Illuminate\Support\Facades\Auth; use Illuminate\Support\ServiceProvider; use Illuminate\Validation\Rules\Password; @@ -17,10 +18,8 @@ class AuthServiceProvider extends ServiceProvider { /** * Bootstrap the application services. - * - * @return void */ - public function boot() + public function boot(): void { // Password Configuration // Changes here must be reflected in ApiDocsGenerate@getValidationAsString. @@ -57,13 +56,17 @@ class AuthServiceProvider extends ServiceProvider /** * Register the application services. - * - * @return void */ - public function register() + public function register(): void { Auth::provider('external-users', function ($app, array $config) { return new ExternalBaseUserProvider($config['model']); }); + + // Bind and provide the default system user as a singleton to the app instance when needed. + // This effectively "caches" fetching the user at an app-instance level. + $this->app->singleton('users.default', function () { + return User::query()->where('system_name', '=', 'public')->first(); + }); } }