Skip to content

Commit 85dd715

Browse files
authored
Merge pull request #4903 from BookStackApp/laravel10
Framework: Upgrade from Laravel 9 to 10
2 parents 0776152 + 28d6292 commit 85dd715

File tree

110 files changed

+932
-1232
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+932
-1232
lines changed

app/Access/Controllers/MfaTotpController.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,25 @@ class MfaTotpController extends Controller
1919

2020
protected const SETUP_SECRET_SESSION_KEY = 'mfa-setup-totp-secret';
2121

22+
public function __construct(
23+
protected TotpService $totp
24+
) {
25+
}
26+
2227
/**
2328
* Show a view that generates and displays a TOTP QR code.
2429
*/
25-
public function generate(TotpService $totp)
30+
public function generate()
2631
{
2732
if (session()->has(static::SETUP_SECRET_SESSION_KEY)) {
2833
$totpSecret = decrypt(session()->get(static::SETUP_SECRET_SESSION_KEY));
2934
} else {
30-
$totpSecret = $totp->generateSecret();
35+
$totpSecret = $this->totp->generateSecret();
3136
session()->put(static::SETUP_SECRET_SESSION_KEY, encrypt($totpSecret));
3237
}
3338

34-
$qrCodeUrl = $totp->generateUrl($totpSecret, $this->currentOrLastAttemptedUser());
35-
$svg = $totp->generateQrCodeSvg($qrCodeUrl);
39+
$qrCodeUrl = $this->totp->generateUrl($totpSecret, $this->currentOrLastAttemptedUser());
40+
$svg = $this->totp->generateQrCodeSvg($qrCodeUrl);
3641

3742
$this->setPageTitle(trans('auth.mfa_gen_totp_title'));
3843

@@ -56,7 +61,7 @@ public function confirm(Request $request)
5661
'code' => [
5762
'required',
5863
'max:12', 'min:4',
59-
new TotpValidationRule($totpSecret),
64+
new TotpValidationRule($totpSecret, $this->totp),
6065
],
6166
]);
6267

@@ -87,7 +92,7 @@ public function verify(Request $request, LoginService $loginService, MfaSession
8792
'code' => [
8893
'required',
8994
'max:12', 'min:4',
90-
new TotpValidationRule($totpSecret),
95+
new TotpValidationRule($totpSecret, $this->totp),
9196
],
9297
]);
9398

app/Access/Mfa/TotpValidationRule.php

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,26 @@
22

33
namespace BookStack\Access\Mfa;
44

5-
use Illuminate\Contracts\Validation\Rule;
5+
use Closure;
6+
use Illuminate\Contracts\Validation\ValidationRule;
67

7-
class TotpValidationRule implements Rule
8+
class TotpValidationRule implements ValidationRule
89
{
9-
protected $secret;
10-
protected $totpService;
11-
1210
/**
1311
* Create a new rule instance.
1412
* Takes the TOTP secret that must be system provided, not user provided.
1513
*/
16-
public function __construct(string $secret)
17-
{
18-
$this->secret = $secret;
19-
$this->totpService = app()->make(TotpService::class);
14+
public function __construct(
15+
protected string $secret,
16+
protected TotpService $totpService,
17+
) {
2018
}
2119

22-
/**
23-
* Determine if the validation rule passes.
24-
*/
25-
public function passes($attribute, $value)
26-
{
27-
return $this->totpService->verifyCode($value, $this->secret);
28-
}
29-
30-
/**
31-
* Get the validation error message.
32-
*/
33-
public function message()
20+
public function validate(string $attribute, mixed $value, Closure $fail): void
3421
{
35-
return trans('validation.totp');
22+
$passes = $this->totpService->verifyCode($value, $this->secret);
23+
if (!$passes) {
24+
$fail(trans('validation.totp'));
25+
}
3626
}
3727
}

app/App/Providers/AppServiceProvider.php

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,28 +25,36 @@ class AppServiceProvider extends ServiceProvider
2525
* Custom container bindings to register.
2626
* @var string[]
2727
*/
28-
public $bindings = [
28+
public array $bindings = [
2929
ExceptionRenderer::class => BookStackExceptionHandlerPage::class,
3030
];
3131

3232
/**
3333
* Custom singleton bindings to register.
3434
* @var string[]
3535
*/
36-
public $singletons = [
36+
public array $singletons = [
3737
'activity' => ActivityLogger::class,
3838
SettingService::class => SettingService::class,
3939
SocialDriverManager::class => SocialDriverManager::class,
4040
CspService::class => CspService::class,
4141
HttpRequestService::class => HttpRequestService::class,
4242
];
4343

44+
/**
45+
* Register any application services.
46+
*/
47+
public function register(): void
48+
{
49+
$this->app->singleton(PermissionApplicator::class, function ($app) {
50+
return new PermissionApplicator(null);
51+
});
52+
}
53+
4454
/**
4555
* Bootstrap any application services.
46-
*
47-
* @return void
4856
*/
49-
public function boot()
57+
public function boot(): void
5058
{
5159
// Set root URL
5260
$appUrl = config('app.url');
@@ -67,16 +75,4 @@ public function boot()
6775
'page' => Page::class,
6876
]);
6977
}
70-
71-
/**
72-
* Register any application services.
73-
*
74-
* @return void
75-
*/
76-
public function register()
77-
{
78-
$this->app->singleton(PermissionApplicator::class, function ($app) {
79-
return new PermissionApplicator(null);
80-
});
81-
}
8278
}

app/App/Providers/AuthServiceProvider.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@ class AuthServiceProvider extends ServiceProvider
1818
{
1919
/**
2020
* Bootstrap the application services.
21-
*
22-
* @return void
2321
*/
24-
public function boot()
22+
public function boot(): void
2523
{
2624
// Password Configuration
2725
// Changes here must be reflected in ApiDocsGenerate@getValidationAsString.
@@ -58,10 +56,8 @@ public function boot()
5856

5957
/**
6058
* Register the application services.
61-
*
62-
* @return void
6359
*/
64-
public function register()
60+
public function register(): void
6561
{
6662
Auth::provider('external-users', function ($app, array $config) {
6763
return new ExternalBaseUserProvider($config['model']);

app/App/Providers/EventServiceProvider.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,16 @@ class EventServiceProvider extends ServiceProvider
2929

3030
/**
3131
* Register any events for your application.
32-
*
33-
* @return void
3432
*/
35-
public function boot()
33+
public function boot(): void
3634
{
3735
//
3836
}
3937

4038
/**
4139
* Determine if events and listeners should be automatically discovered.
42-
*
43-
* @return bool
4440
*/
45-
public function shouldDiscoverEvents()
41+
public function shouldDiscoverEvents(): bool
4642
{
4743
return false;
4844
}

app/App/Providers/RouteServiceProvider.php

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,8 @@ class RouteServiceProvider extends ServiceProvider
2424

2525
/**
2626
* Define your route model bindings, pattern filters, etc.
27-
*
28-
* @return void
2927
*/
30-
public function boot()
28+
public function boot(): void
3129
{
3230
$this->configureRateLimiting();
3331

@@ -41,10 +39,8 @@ public function boot()
4139
* Define the "web" routes for the application.
4240
*
4341
* These routes all receive session state, CSRF protection, etc.
44-
*
45-
* @return void
4642
*/
47-
protected function mapWebRoutes()
43+
protected function mapWebRoutes(): void
4844
{
4945
Route::group([
5046
'middleware' => 'web',
@@ -65,10 +61,8 @@ protected function mapWebRoutes()
6561
* Define the "api" routes for the application.
6662
*
6763
* These routes are typically stateless.
68-
*
69-
* @return void
7064
*/
71-
protected function mapApiRoutes()
65+
protected function mapApiRoutes(): void
7266
{
7367
Route::group([
7468
'middleware' => 'api',
@@ -81,10 +75,8 @@ protected function mapApiRoutes()
8175

8276
/**
8377
* Configure the rate limiters for the application.
84-
*
85-
* @return void
8678
*/
87-
protected function configureRateLimiting()
79+
protected function configureRateLimiting(): void
8880
{
8981
RateLimiter::for('api', function (Request $request) {
9082
return Limit::perMinute(60)->by($request->user()?->id ?: $request->ip());

app/App/Providers/ThemeServiceProvider.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,17 @@ class ThemeServiceProvider extends ServiceProvider
1010
{
1111
/**
1212
* Register services.
13-
*
14-
* @return void
1513
*/
16-
public function register()
14+
public function register(): void
1715
{
1816
// Register the ThemeService as a singleton
1917
$this->app->singleton(ThemeService::class, fn ($app) => new ThemeService());
2018
}
2119

2220
/**
2321
* Bootstrap services.
24-
*
25-
* @return void
2622
*/
27-
public function boot()
23+
public function boot(): void
2824
{
2925
// Boot up the theme system
3026
$themeService = $this->app->make(ThemeService::class);

app/App/Providers/TranslationServiceProvider.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@ class TranslationServiceProvider extends BaseProvider
1111
{
1212
/**
1313
* Register the service provider.
14-
*
15-
* @return void
1614
*/
17-
public function register()
15+
public function register(): void
1816
{
1917
$this->registerLoader();
2018

@@ -41,10 +39,8 @@ public function register()
4139
/**
4240
* Register the translation line loader.
4341
* Overrides the default register action from Laravel so a custom loader can be used.
44-
*
45-
* @return void
4642
*/
47-
protected function registerLoader()
43+
protected function registerLoader(): void
4844
{
4945
$this->app->singleton('translation.loader', function ($app) {
5046
return new FileLoader($app['files'], $app['path.lang']);

app/App/Providers/ViewTweaksServiceProvider.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@ class ViewTweaksServiceProvider extends ServiceProvider
1212
{
1313
/**
1414
* Bootstrap services.
15-
*
16-
* @return void
1715
*/
18-
public function boot()
16+
public function boot(): void
1917
{
2018
// Set paginator to use bootstrap-style pagination
2119
Paginator::useBootstrap();

app/Config/app.php

Lines changed: 11 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010

1111
use Illuminate\Support\Facades\Facade;
12+
use Illuminate\Support\ServiceProvider;
1213

1314
return [
1415

@@ -113,46 +114,22 @@
113114
],
114115

115116
// Application Service Providers
116-
'providers' => [
117-
118-
// Laravel Framework Service Providers...
119-
Illuminate\Auth\AuthServiceProvider::class,
120-
Illuminate\Broadcasting\BroadcastServiceProvider::class,
121-
Illuminate\Bus\BusServiceProvider::class,
122-
Illuminate\Cache\CacheServiceProvider::class,
123-
Illuminate\Foundation\Providers\ConsoleSupportServiceProvider::class,
124-
Illuminate\Cookie\CookieServiceProvider::class,
125-
Illuminate\Database\DatabaseServiceProvider::class,
126-
Illuminate\Encryption\EncryptionServiceProvider::class,
127-
Illuminate\Filesystem\FilesystemServiceProvider::class,
128-
Illuminate\Foundation\Providers\FoundationServiceProvider::class,
129-
Illuminate\Hashing\HashServiceProvider::class,
130-
Illuminate\Mail\MailServiceProvider::class,
131-
Illuminate\Notifications\NotificationServiceProvider::class,
132-
Illuminate\Pagination\PaginationServiceProvider::class,
133-
Illuminate\Pipeline\PipelineServiceProvider::class,
134-
Illuminate\Queue\QueueServiceProvider::class,
135-
Illuminate\Redis\RedisServiceProvider::class,
136-
Illuminate\Auth\Passwords\PasswordResetServiceProvider::class,
137-
Illuminate\Session\SessionServiceProvider::class,
138-
Illuminate\Validation\ValidationServiceProvider::class,
139-
Illuminate\View\ViewServiceProvider::class,
140-
117+
'providers' => ServiceProvider::defaultProviders()->merge([
141118
// Third party service providers
142119
Barryvdh\DomPDF\ServiceProvider::class,
143120
Barryvdh\Snappy\ServiceProvider::class,
144121
SocialiteProviders\Manager\ServiceProvider::class,
145122

146123
// BookStack custom service providers
147-
\BookStack\App\Providers\ThemeServiceProvider::class,
148-
\BookStack\App\Providers\AppServiceProvider::class,
149-
\BookStack\App\Providers\AuthServiceProvider::class,
150-
\BookStack\App\Providers\EventServiceProvider::class,
151-
\BookStack\App\Providers\RouteServiceProvider::class,
152-
\BookStack\App\Providers\TranslationServiceProvider::class,
153-
\BookStack\App\Providers\ValidationRuleServiceProvider::class,
154-
\BookStack\App\Providers\ViewTweaksServiceProvider::class,
155-
],
124+
BookStack\App\Providers\ThemeServiceProvider::class,
125+
BookStack\App\Providers\AppServiceProvider::class,
126+
BookStack\App\Providers\AuthServiceProvider::class,
127+
BookStack\App\Providers\EventServiceProvider::class,
128+
BookStack\App\Providers\RouteServiceProvider::class,
129+
BookStack\App\Providers\TranslationServiceProvider::class,
130+
BookStack\App\Providers\ValidationRuleServiceProvider::class,
131+
BookStack\App\Providers\ViewTweaksServiceProvider::class,
132+
])->toArray(),
156133

157134
// Class Aliases
158135
// This array of class aliases to be registered on application start.

app/Config/cache.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@
5353

5454
'file' => [
5555
'driver' => 'file',
56-
'path' => storage_path('framework/cache'),
56+
'path' => storage_path('framework/cache/data'),
57+
'lock_path' => storage_path('framework/cache/data'),
5758
],
5859

5960
'memcached' => [

app/Config/hashing.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
// passwords are hashed using the Bcrypt algorithm. This will allow you
2222
// to control the amount of time it takes to hash the given password.
2323
'bcrypt' => [
24-
'rounds' => env('BCRYPT_ROUNDS', 10),
24+
'rounds' => env('BCRYPT_ROUNDS', 12),
25+
'verify' => true,
2526
],
2627

2728
// Argon Options

0 commit comments

Comments
 (0)